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 ThreadPool management with callback implementation, granular control, customizable concurrency, and support for diverse task submissions.
PowerPool powerPool = new PowerPool(new ThreadPoolOption() { MaxThreads = 3 });
powerPool.QueueWorkItem(() =>
{
// DO SOMETHING
return result;
});
With callback
PowerPool powerPool = new PowerPool(new ThreadPoolOption() { MaxThreads = 3 });
powerPool.QueueWorkItem(() =>
{
// DO SOMETHING
return result;
}, (res) =>
{
// this callback of thread
// running result: res.Result
});
Stop all threads
powerPool.Stop();
Blocks the calling thread until all of the threads terminates.
powerPool.Wait();
Pause threads
PowerPool powerPool = new PowerPool(new ThreadPoolOption());
string id = powerPool.QueueWorkItem(() =>
{
while (true)
{
// Pause here when user call Pause()
powerPool.PauseIfRequested();
// DO SOMETHING
}
});
// DO SOMETHING
powerPool.Pause(id); // Pause by ID
powerPool.Pause(); // Pause all running thread
powerPool.Resume(true); // Resume all thread
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.
-
WaitAsync()
Blocks the calling thread until all of the threads terminates.
Task
Stop(bool forceStop = false)
Stop all threads
-
StopAsync(bool forceStop = false)
Stop all threads
Task
Stop(string id, bool forceStop = false)
Stop thread by id
If thread is in progress during the invocation
StopAsync(string id, bool forceStop = false)
Stop thread by id
(Task) If thread is in progress during the invocation
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
ThreadPoolOption ThreadPoolOption; // Get, Set
int WaitingThreadCount; // Get
IEnumerable<string> WaitingThreadList; // Get
int RunningThreadCount; // Get
IEnumerable<string> RunningThreadList; // Get