DPStano 15 Posted May 15, 2020 (edited) I have multiple tasks like var Task := CreateTask( procedure(const Task: IOmniTask) begin end).Unobserved.Join(GlobalTaskGroup); Parallel.Start(Task , Parallel.TaskConfig.CancelWith(GlobalCancellationToken)); they can run for various times from seconds to minutes and some tasks can even run multiple times at once, and I need to terminate them and wait for termination all living task (some of them are already finished) at some point GlobalCancellationToken.Signal; GlobalTaskGroup.WaitForAll(); so the question is how to properly manage task group to keep just living tasks in it? ... i don't see any code how could TaskGroup remove task after its termination, it will keep reference until the task is explicitly removed by calling TaskGroup.remove. Edited May 15, 2020 by DPStano Share this post Link to post
Primož Gabrijelčič 223 Posted May 15, 2020 Does this not already work out of the box? If a task is finished, WaitForAll should now that. Share this post Link to post
DPStano 15 Posted May 15, 2020 yes it works but without clearing taskgroup i can have taskgroup with like 100k finished tasks which won't be very effective at first i was searching for something like CreateTask( procedure(const Task: IOmniTask) begin try // do some work finally GlobalTaskGroup.Remove(Task) end end).Unobserved.Join(GlobalTaskGroup); but IOmniTaskGroup is not a group of IOmniTask but a group of IOmniTaskControl but i found solution OnTerminated can give me IOmniTaskControl so i'll unregister task from group there Share this post Link to post
Primož Gabrijelčič 223 Posted May 15, 2020 Indeed, OnTerminated is the correct approach. Share this post Link to post