Skip to content

Work Group

ZjzMisaka edited this page Nov 23, 2024 · 14 revisions

A Group can be set for a work using WorkOption.Group.

powerPool.QueueWorkItem(() =>
{
    // Do something
}, new WorkOption()
{
    Group = "GroupName"
});

This way, the execution of works can be controlled in batches through the already set group.

powerPool.GetGroup("GroupName").Wait();
powerPool.Wait(powerPool.GetGroupMemberList("GroupName"));

Group Object

PowerPool.GetGroup(string groupName) will return a group object, which have funcions for control the works belonging to the group.

Properties

[Get only]
Group name

string Name;

Group Control

The group object has the following functions for group control, similar to the pool and work control.

name summary result
Add(string workID) Add work to group. Returns false if the work does not exist.
Modifies WorkOption.Group.
Remove(string workID) Remove work from group. Returns false if work does not exist, or if the work does not belong to the group
Wait() Wait until all the work belonging to the group is done.
WaitAsync() Wait until all the work belonging to the group is done.
Fetch(bool removeAfterFetch = false) Fetch the work result. Return a list of work result
Fetch(bool removeAfterFetch = false) Fetch the work result. Return a list of work result
Fetch(Func<ExecuteResult, bool> predicate, bool removeAfterFetch = false) Fetch the work result. Return a list of work result
FetchAsync(bool removeAfterFetch = false) Fetch the work result. Return a list of work result
FetchAsync(bool removeAfterFetch = false) Fetch the work result. Return a list of work result
Stop(bool forceStop = false) Stop all the work belonging to the group. Return false if no thread running
Pause() Pause all the work belonging to the group. Return a list of IDs for work that doesn't exist
Resume() Resume all the work belonging to the group. Return a list of IDs for work that doesn't exist
Cancel() Cancel all the work belonging to the group. Return a list of IDs for work that doesn't exist