-
Notifications
You must be signed in to change notification settings - Fork 16
Home
ZjzMisaka edited this page Mar 25, 2026
·
60 revisions

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.
This project is currently a Seed Project within the .NET Foundation. This means it is an "up and coming" project within the foundation to grow its community and ecosystem.
- Provides rich, ultra-fine-grained control primitives spanning the entire work lifecycle.
- Offers native async support. PTP manages all continuations of an asynchronous work directly without sacrificing async semantics and essential characteristics, rather than simply wrapping
Task.Run. - Grants asynchronous works the exact same control features as synchronous ones via a unified interface, allowing transparent and seamless interleaving of synchronous and asynchronous workloads.
- Leverages optimizations like CAS, work-stealing, and heuristic debounce slgorithms. This maintains performance close to the native thread pool while implementing advanced functionality, thereby minimizing the overhead caused by secondary encapsulation.
If you want to include PowerThreadPool in your project, you can install it directly from NuGet.
Support: Net40+ | Net5.0+ | netstandard2.0+
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.QueueWorkItem(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.QueueWorkItem(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.QueueWorkItem(async () =>
{
// Do something
// await ...;
}, new WorkOption()
{
// Some options
});// Sync
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, *);
// Async
WorkID QueueWorkItem<T1, ...>(Func<T1, ..., Task> asyncFunc, T1 param1, ..., _, *);
WorkID QueueWorkItem(Func<Task> asyncFunc, _, *);
WorkID QueueWorkItem(Func<object[], Task> asyncFunc, object[] param, _, *);
WorkID QueueWorkItem<T1, ..., TResult>(Func<T1, ..., Task<TResult>> asyncFunc, T1 param1, ..., _, *);
WorkID QueueWorkItem<TResult>(Func<Task<TResult>> asyncFunc, _, *);
WorkID QueueWorkItem<TResult>(Func<object[], Task<TResult>> asyncFunc, object[] param, _, *);| Wildcard | Explanation |
|---|---|
| * |
WorkOption | WorkOption<T>: The work option to customize the behavior of the work.Action<ExecuteResult<T>>: The callback to be invoked when the work is completed. |
| ... | Up to 5 type parameters are supported. |
| _ | An out parameter (Task | Task<ExecuteResult<TResult>>) that returns a Task representing the asynchronous execution of asyncFunc. |
powershell -File build.ps1 -Version {Version}Testing And Performance Analysis | Feature Comparison | Knowledge Base
Get involved: Join our growing community
- 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)
Core
Results
Options