1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| var
ListTasks: array[0..n] of ITask; // uses System.Threading
begin
// création d'une tâche
ListTasks[0] := TTask.Run(procedure
begin
MaProcQuiFaitQqch;
TThread.Synchronize(TThread.Current,
procedure
begin
Memo.Lines.Add('Début');
end));
// création de n tâches ...
// tâche exécutée quand les tâches de la liste sont terminées
// utiliser WaitForAny pour exécuter le code quand au moins une
// tâche est terminée
TTask.Run(procedure
begin
TTask.WaitForAll(ListTasks);
MaProcQuiFaitQqch_Suite;
TThread.Synchronize(TThread.Current,
procedure
begin
Memo.Lines.Add('Terminé')
end);
end);
end; |
Partager