Jump to content
DPStano

[Q] OmniThreadLibrary - TaskGroup

Recommended Posts

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 by DPStano

Share this post


Link to post

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×