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.
Access the Wiki in English | 中文 | 日本語.
Visit the DeepWiki for more information.
powershell -File build.ps1 -Version {Version}If you want to include PowerThreadPool in your project, you can install it directly from NuGet.
Support: Net40+ | Net5.0+ | netstandard2.0+
- Sync | Async
- Pool Control | Work Control
- Divide And Conquer
- Thread Pool Sizing
- Work Callback | Default Callback
- Rejection Policy
- Parallel Execution
- Work Priority | Thread Priority
- Error Handling
- Work Timeout | Cumulative Work Timeout
- Work Dependency
- Work Group
- Events
- Runtime Status
- Running Timer
- Queue Type (FIFO | LIFO | Deque | Custom)
- Load Balancing
- Low-Contention Design
PTP is designed to be out-of-the-box. For simple works, you can get started without any complex configuration.
PowerPool powerPool = new PowerPool();
// Sync
powerPool.QueueWorkItem(() =>
{
// Do something
});
// Async
powerPool.QueueWorkItemAsync(async () =>
{
// Do something
// await ...;
});PowerPool powerPool = new PowerPool(new PowerPoolOption() { /* Some options */ });
// Sync
powerPool.QueueWorkItem(() =>
{
// Do something
return result;
}, (res) =>
{
// Callback of the work
});
// Async
powerPool.QueueWorkItemAsync(async () =>
{
// Do something
// await ...;
}, (res) =>
{
// Callback of the work
});PowerPool powerPool = new PowerPool(new PowerPoolOption() { /* Some options */ });
// Sync
powerPool.QueueWorkItem(() =>
{
// Do something
return result;
}, new WorkOption()
{
// Some options
});
// Async
powerPool.QueueWorkItemAsync(async () =>
{
// Do something
// await ...;
}, new WorkOption()
{
// Some options
});WorkID QueueWorkItem<T1, ...>(Action<T1, ...> action, T1 param1, ..., *);
WorkID QueueWorkItem(Action action, *);
WorkID QueueWorkItem(Action<object[]> action, object[] param, *);
WorkID QueueWorkItem<T1, ..., TResult>(Func<T1, ..., TResult> function, T1 param1, ..., *);
WorkID QueueWorkItem<TResult>(Func<TResult> function, *);
WorkID QueueWorkItem<TResult>(Func<object[], TResult> function, object[] param, *);
WorkID QueueWorkItemAsync(Func<Task> asyncFunc, *);
WorkID QueueWorkItemAsync<TResult>(Func<Task<TResult>> asyncFunc, *);
WorkID QueueWorkItemAsync(Func<Task> asyncFunc, out Task task, *);
WorkID QueueWorkItemAsync<TResult>(Func<Task<TResult>> asyncFunc, out Task<ExecuteResult<TResult>> task, *);- Asterisk (*) denotes an optional parameter, either a WorkOption or a delegate (
Action<ExecuteResult<object>>orAction<ExecuteResult<TResult>>), depending on whether the first parameter is an Action or a Func. - In places where you see ellipses (...), you can provide up to five generic type parameters.
Testing And Performance Analysis | Feature Comparison
Get involved: Join our growing community
Thanks goes to these wonderful people (emoji key):
一条咸鱼 💻 |
ZjzMisaka 💻 🚧 📖 |
r00tee 🤔 |
aadog 🐛 |
RookieZWH 💬 |
hebinary 💬 |
lindexi 🐛 |
This project follows the all-contributors specification. Contributions of any kind welcome!