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()
Stop all threads
-
StopAsync()
Stop all threads
Task
PauseIfRequested()
Call this function inside the thread logic where you want to pause when user call Pause(...)
-
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
int WaitingThreadList; // Get
int RunningThreadCount; // Get
int RunningThreadList; // Get