A comprehensive and efficient low-contention thread pool for easily managing both sync and async workloads. It provides granular work control, flexible concurrency, and robust error handling.
Enables efficient thread pool management with callback implementation, granular control, customizable concurrency, and support for diverse task submissions.
PowerPool powerPool = new PowerPool(new ThreadPoolOption() { /* Some options */ });
powerPool.QueueWorkItem(() =>
{
// DO SOMETHING
});
With callback
PowerPool powerPool = new PowerPool(new ThreadPoolOption() { /* Some options */ });
powerPool.QueueWorkItem(() =>
{
// DO SOMETHING
return result;
}, (res) =>
{
// this callback of thread
// running result: res.Result
});
With option
PowerPool powerPool = new PowerPool(new ThreadPoolOption() { /* Some options */ });
powerPool.QueueWorkItem(() =>
{
// DO SOMETHING
return result;
}, new ThreadOption()
{
// Some options
});
API Summary
PowerPool
name
summary
result
QueueWorkItem<...>(...)
Queues a method for execution. The method executes when a thread pool thread becomes available.
thread id
Wait()
Blocks the calling thread until all of the threads terminates.
-
Wait(string id)
Blocks the calling thread until the thread terminates.
Return false if the thread isn't running
WaitAsync()
Blocks the calling thread until all of the threads terminates.
Task
WaitAsync(string id)
Blocks the calling thread until the thread terminates.
Return false if the thread isn't running
Stop(bool forceStop = false)
Stop all threads. If forceStop is true, Thread.Interrupt() and Thread.Join() will be called.
Return false if no thread running
StopAsync(bool forceStop = false)
Stop all threads. If forceStop is true, Thread.Interrupt() and Thread.Join() will be called.
(Task) Return false if no thread running
Stop(string id, bool forceStop = false)
Stop thread by id. If forceStop is true, Thread.Interrupt() and Thread.Join() will be called.
Return false if the thread isn't running
StopAsync(string id, bool forceStop = false)
Stop thread by id. If forceStop is true, Thread.Interrupt() and Thread.Join() will be called.
(Task) Return false if the thread isn't running
PauseIfRequested()
Call this function inside the thread logic where you want to pause when user call Pause(...)
-
StopIfRequested()
Call this function inside the thread logic where you want to stop when user call Stop(...)
-
CheckIfRequestedStop()
Call this function inside the thread logic where you want to check if requested stop (if user call Stop(...))
-
Pause()
Pause all threads
-
Resume(bool resumeThreadPausedById = false)
Resume all threads
-
Pause(string id)
Pause thread by id
-
Resume(string id)
Resume thread by id
-
Cancel()
Cancel all tasks that have not started running
-
Cancel(string id)
Cancel the task by id if the task has not started running
is succeed
API List
PowerPool
Properties
int IdleThreadCount; // Get
ThreadPoolOption ThreadPoolOption; // Get, Set
int WaitingWorkCount; // Get
IEnumerable<string> WaitingWorkerList; // Get
int RunningWorkerCount; // Get
IEnumerable<string> RunningWorkList; // Get
string ID; // Get
TResult Result; // Get
Status Status; // Get
Exception Exception; // Get
Status
enum Status { Succeed, Failed }
ThreadPoolOption
Properties
int MaxThreads; // Get, Set
TimeoutOption Timeout; // Get, Set
TimeoutOption DefaultThreadTimeout; // Get, Set
Action<ExecuteResult<object>> DefaultCallback; // Get, Set
ThreadOption
Properties
TimeoutOption Timeout; // Get, Set
Action<ExecuteResult<TResult>> Callback; // Get, Set
int Priority; // Get, Set
DestroyThreadOption DestroyThreadOption; // Get, Set
DestroyThreadOption
Properties
int KeepAliveTime; // Get, Set
int MinThreads; // Get, Set