Skip to content

API Summary

ZjzMisaka edited this page Jan 24, 2026 · 38 revisions
name summary result
QueueWorkItem<...>(...) Queues a sync/async work for execution. work id
PauseIfRequested() Call this function inside the work logic where you want to pause when user call Pause(...) -
StopIfRequested(Func beforeStop = null) Call this function inside the work logic where you want to stop when user call Stop(...)
To exit the logic, the function will throw a PowerThreadPool.Exceptions.WorkStopException. Do not catch it.
If you do not want to exit the logic in this way (for example, if you have some unmanaged resources that need to be released before exiting), it is recommended to use CheckIfRequestedStop.
-
CheckIfRequestedStop() Call this function inside the work logic where you want to check if requested stop (if user call Stop(...))
When returning true, you can perform some pre operations (such as releasing unmanaged resources) and then safely exit the logic.
Requested stop or not
Wait(bool helpWhileWaiting = false) Blocks the calling thread until all of the works terminates. -
Wait(CancellationToken cancellationToken, bool helpWhileWaiting = false) Blocks the calling thread until all of the works terminates. -
Wait(WorkID id, bool helpWhileWaiting = false) Blocks the calling thread until the work terminates. Return false if the work isn't running
Wait(WorkID id, CancellationToken cancellationToken, bool helpWhileWaiting = false) Blocks the calling thread until the work terminates. Return false if the work isn't running
Wait(IEnumerable idList, bool helpWhileWaiting = false) Blocks the calling thread until the work terminates. Return a list of ID for work that doesn't running
Wait(IEnumerable idList, CancellationToken cancellationToken, bool helpWhileWaiting = false) Blocks the calling thread until the work terminates. Return a list of ID for work that doesn't running
WaitAsync(bool helpWhileWaiting = false) Blocks the calling thread until all of the works terminates. Task
WaitAsync(CancellationToken cancellationToken, bool helpWhileWaiting = false) Blocks the calling thread until all of the works terminates. Task
WaitAsync(WorkID id, bool helpWhileWaiting = false) Blocks the calling thread until the work terminates. (Task) Return false if the work isn't running
WaitAsync(WorkID id, CancellationToken cancellationToken, bool helpWhileWaiting = false) Blocks the calling thread until the work terminates. (Task) Return false if the work isn't running
WaitAsync(IEnumerable idList, bool helpWhileWaiting = false) Blocks the calling thread until the work terminates. (Task) Return a list of ID for work that doesn't running
WaitAsync(IEnumerable idList, CancellationToken cancellationToken, bool helpWhileWaiting = false) Blocks the calling thread until the work terminates. (Task) Return a list of ID for work that doesn't running
Fetch(WorkID id, bool removeAfterFetch = false, bool helpWhileWaiting = false) Fetch the work result. Work result
Fetch(WorkID id, CancellationToken cancellationToken, bool removeAfterFetch = false, bool helpWhileWaiting = false) Fetch the work result. Work result
Fetch(WorkID id, bool removeAfterFetch = false, bool helpWhileWaiting = false) Fetch the work result. Work result
Fetch(WorkID id, CancellationToken cancellationToken, bool removeAfterFetch = false, bool helpWhileWaiting = false) Fetch the work result. Work result
Fetch(IEnumerable idList, bool removeAfterFetch = false, bool helpWhileWaiting = false) Fetch the work result. Work result
Fetch(IEnumerable idList, CancellationToken cancellationToken, bool removeAfterFetch = false, bool helpWhileWaiting = false) Fetch the work result. Work result
Fetch(IEnumerable idList, bool removeAfterFetch = false, bool helpWhileWaiting = false) Fetch the work result. Work result
Fetch(IEnumerable idList, CancellationToken cancellationToken, bool removeAfterFetch = false, bool helpWhileWaiting = false) Fetch the work result. Work result
Fetch(Func<ExecuteResult, bool> predicate, bool removeAfterFetch = false, bool helpWhileWaiting = false) Fetch the work result. Return a list of work result
FetchAsync(WorkID id, bool removeAfterFetch = false) Fetch the work result. (Task) Work result
FetchAsync(WorkID id, CancellationToken cancellationToken, bool removeAfterFetch = false) Fetch the work result. (Task) Work result
FetchAsync(WorkID id, bool removeAfterFetch = false) Fetch the work result. (Task) Work result
FetchAsync(WorkID id, CancellationToken cancellationToken, bool removeAfterFetch = false) Fetch the work result. (Task) Work result
FetchAsync(IEnumerable idList, bool removeAfterFetch = false) Fetch the work result. (Task) Work result
FetchAsync(IEnumerable idList, CancellationToken cancellationToken, bool removeAfterFetch = false) Fetch the work result. (Task) Work result
FetchAsync(IEnumerable idList, bool removeAfterFetch = false) Fetch the work result. (Task) Work result
FetchAsync(IEnumerable idList, CancellationToken cancellationToken, bool removeAfterFetch = false) Fetch the work result. (Task) Work result
Stop() Stop all works. Return false if no thread running
ForceStop() Force stop all works. Thread.Interrupt() will be called. Return false if no thread running
Stop(WorkID id) Stop work by id. Return false if the work does not exist or has been done
ForceStop(WorkID id) Force stop work by id. Thread.Interrupt() will be called. Return false if the work does not exist or has been done
Stop(IEnumerable idList) Stop works by id list. Return a list of ID for work that either doesn't exist or hasn't been done
ForceStop(IEnumerable idList) Stop works by id list. Thread.Interrupt() will be called. Return a list of ID for work that either doesn't exist or hasn't been done
Pause() Pause all threads -
Pause(WorkID id) Pause thread by id If the work id exists
Pause(IEnumerable idList) Pause threads by id list Return a list of IDs for work that doesn't exist
Resume(bool resumeThreadPausedById = false) Resume all threads -
Resume(WorkID id) Resume thread by id If the work id exists
Resume(IEnumerable idList) Resume threads by id list Return a list of IDs for work that doesn't exist
Cancel() Cancel all works that have not started running -
Cancel(WorkID id) Cancel the work by id if the work has not started running is succeed
GetGroup() Get group object Group object
GetGroupMemberSet() Get all members of a group Work id list
AddWorkToGroup(string groupName, WorkID workID) Add work to group Returns false if the work does not exist.
Modifies WorkOption.Group.
RemoveWorkFromGroup(string groupName, WorkID workID) Remove work from group Returns false if either the work or the group does not exist, or if the work does not belong to the group.
SetGroupRelation(string parentGroup, string childGroup) Set group relation
RemoveGroupRelation(string parentGroup, string childGroup = null) Remove group relation is succeed
ResetGroupRelation() Reset group relation
For(int start, int end, Action body, int step = 1, string groupName = null) Creates a parallel loop that executes iterations from start to end. Group object
For(int start, int end, Func<int, Task> body, int step = 1, string groupName = null) Creates a parallel loop that executes iterations from start to end. Group object
For(int start, int end, IList source, Action body, int step = 1, string groupName = null) Creates a parallel loop that executes iterations from start to end. Group object
For(int start, int end, IList source, Func<TSource, Task> body, int step = 1, string groupName = null) Group object
For(int start, int end, IList source, Action<TSource, int> body, int step = 1, string groupName = null) Creates a parallel loop that executes iterations from start to end. Group object
For(int start, int end, IList source, Func<TSource, int, Task> body, int step = 1, string groupName = null) Creates a parallel loop that executes iterations from start to end. Group object
ForEach(IEnumerable source, Action body, string groupName = null) Creates a parallel loop that executes a specified action for each element in the source collection. Group object
ForEach(IEnumerable source, Func<TSource, Task> body, string groupName = null) Creates a parallel loop that executes a specified action for each element in the source collection. Group object
ForEach(IEnumerable source, Action<TSource, int> body, string groupName = null) Creates a parallel loop that executes a specified action for each element in the source collection. Group object
ForEach(IEnumerable source, Func<TSource, int, Task> body, string groupName = null) Creates a parallel loop that executes a specified action for each element in the source collection. Group object
Watch(ConcurrentObservableCollection source, Action body, bool addBackWhenWorkCanceled = true, bool addBackWhenWorkStopped = true, bool addBackWhenWorkFailed = true, string groupName = null) Watches an observable collection for changes and processes each element in the collection using the specified action. Group object
Watch(ConcurrentObservableCollection source, Func<TSource, Task> body, bool addBackWhenWorkCanceled = true, bool addBackWhenWorkStopped = true, bool addBackWhenWorkFailed = true, string groupName = null) Watches an observable collection for changes and processes each element in the collection using the specified action. Group object
StopWatching(ConcurrentObservableCollection source, bool keepRunning = false) Stops watching the observable collection for changes.
ForceStopWatching(ConcurrentObservableCollection source, bool keepRunning = false) Force stops watching the observable collection for changes.
Start() Start the pool, but only if PowerPoolOption.StartSuspended is set to true
ClearResultStorage() Clear result storage
ClearResultStorage(WorkID workID) Clear result storage
ClearResultStorage(IEnumerable workIDList) Clear result storage
ClearFailedWorkRecord() Clear failed work record
Dispose() Will try stop, force stop and kill all of the workers.

Clone this wiki locally