PowerThreadPool 1.5.3
.NET 5.0
This package targets .NET 5.0. The package is compatible with this framework or higher.
.NET Framework 4.6
This package targets .NET Framework 4.6. The package is compatible with this framework or higher.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package PowerThreadPool --version 1.5.3
NuGet\Install-Package PowerThreadPool -Version 1.5.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PowerThreadPool" Version="1.5.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PowerThreadPool --version 1.5.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: PowerThreadPool, 1.5.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install PowerThreadPool as a Cake Addin #addin nuget:?package=PowerThreadPool&version=1.5.3 // Install PowerThreadPool as a Cake Tool #tool nuget:?package=PowerThreadPool&version=1.5.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
PowerThreadPool
<img src="https://www.nuget.org/Content/gallery/img/logo-header.svg?sanitize=true" height="30px">
Enables efficient thread pool management with callback implementation, granular control, customizable concurrency, and support for diverse task submissions.
Download
PowerThreadPool is available as Nuget Package now.
Getting started
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. | work 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 | If the work id exists |
Resume(string id) | Resume thread by id | If the work id exists |
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
bool ThreadPoolRunning; // Get
bool ThreadPoolStopping; // Get
int IdleThreadCount; // Get
ThreadPoolOption ThreadPoolOption; // Get, Set
int WaitingWorkCount; // Get
IEnumerable<string> WaitingWorkerList; // Get
int RunningWorkerCount; // Get
IEnumerable<string> RunningWorkList; // Get
Events
event ThreadPoolStartEventHandler ThreadPoolStart;
event ThreadPoolIdleEventHandler ThreadPoolIdle;
event ThreadStartEventHandler ThreadStart;
event ThreadEndEventHandler ThreadEnd;
event ThreadPoolTimeoutEventHandler ThreadPoolTimeout;
event ThreadTimeoutEventHandler ThreadTimeout;
Methods
string QueueWorkItem(Action action, Action<ExcuteResult<object>> callBack = null);
string QueueWorkItem(Action action, ThreadOption option);
string QueueWorkItem(Action<object[]> action, object[] param, Action<ExcuteResult<object>> callBack = null);
string QueueWorkItem(Action<object[]> action, object[] param, ThreadOption option);
string QueueWorkItem<T1>(Action<T1> action, T1 param1, Action<ExcuteResult<object>> callBack = null);
string QueueWorkItem<T1>(Action<T1> action, T1 param1, ThreadOption option);
string QueueWorkItem<T1, T2>(Action<T1, T2> action, T1 param1, T2 param2, Action<ExcuteResult<object>> callBack = null);
string QueueWorkItem<T1, T2>(Action<T1, T2> action, T1 param1, T2 param2, ThreadOption option);
string QueueWorkItem<T1, T2, T3>(Action<T1, T2, T3> action, T1 param1, T2 param2, T3 param3, Action<ExcuteResult<object>> callBack = null);
string QueueWorkItem<T1, T2, T3>(Action<T1, T2, T3> action, T1 param1, T2 param2, T3 param3, ThreadOption option);
string QueueWorkItem<T1, T2, T3, T4>(Action<T1, T2, T3, T4> action, T1 param1, T2 param2, T3 param3, T4 param4, Action<ExcuteResult<object>> callBack = null);
string QueueWorkItem<T1, T2, T3, T4>(Action<T1, T2, T3, T4> action, T1 param1, T2 param2, T3 param3, T4 param4, ThreadOption option);
string QueueWorkItem<T1, T2, T3, T4, T5>(Action<T1, T2, T3, T4, T5> action, T1 param1, T2 param2, T3 param3, T4 param4, T5 param5, Action<ExcuteResult<object>> callBack = null);
string QueueWorkItem<T1, T2, T3, T4, T5>(Action<T1, T2, T3, T4, T5> action, T1 param1, T2 param2, T3 param3, T4 param4, T5 param5, ThreadOption option);
string QueueWorkItem<T1, TResult>(Func<T1, TResult> function, T1 param1, Action<ExcuteResult<TResult>> callBack = null);
string QueueWorkItem<T1, TResult>(Func<T1, TResult> function, T1 param1, ThreadOption option);
string QueueWorkItem<T1, T2, TResult>(Func<T1, T2, TResult> function, T1 param1, T2 param2, Action<ExcuteResult<TResult>> callBack = null);
string QueueWorkItem<T1, T2, TResult>(Func<T1, T2, TResult> function, T1 param1, T2 param2, ThreadOption option);
string QueueWorkItem<T1, T2, T3, TResult>(Func<T1, T2, T3, TResult> function, T1 param1, T2 param2, T3 param3, Action<ExcuteResult<TResult>> callBack = null);
string QueueWorkItem<T1, T2, T3, TResult>(Func<T1, T2, T3, TResult> function, T1 param1, T2 param2, T3 param3, ThreadOption option);
string QueueWorkItem<T1, T2, T3, T4, TResult>(Func<T1, T2, T3, T4, TResult> function, T1 param1, T2 param2, T3 param3, T4 param4, Action<ExcuteResult<TResult>> callBack = null);
string QueueWorkItem<T1, T2, T3, T4, TResult>(Func<T1, T2, T3, T4, TResult> function, T1 param1, T2 param2, T3 param3, T4 param4, ThreadOption option);
string QueueWorkItem<T1, T2, T3, T4, T5, TResult>(Func<T1, T2, T3, T4, T5, TResult> function, T1 param1, T2 param2, T3 param3, T4 param4, T5 param5, Action<ExcuteResult<TResult>> callBack = null);
string QueueWorkItem<T1, T2, T3, T4, T5, TResult>(Func<T1, T2, T3, T4, T5, TResult> function, T1 param1, T2 param2, T3 param3, T4 param4, T5 param5, ThreadOption option);
string QueueWorkItem<TResult>(Func<TResult> function, Action<ExcuteResult<TResult>> callBack = null);
string QueueWorkItem<TResult>(Func<TResult> function, ThreadOption option);
string QueueWorkItem<TResult>(Func<object[], TResult> function, object[] param, Action<ExcuteResult<TResult>> callBack = null);
string QueueWorkItem<TResult>(Func<object[], TResult> function, object[] param, ThreadOption option);
void Wait();
bool Wait(string id);
async Task WaitAsync();
async Task<bool> WaitAsync(string id);
bool Stop(bool forceStop = false);
async Task<bool> StopAsync(bool forceStop = false);
bool Stop(string id, bool forceStop = false);
async Task<bool> StopAsync(string id, bool forceStop = false);
void PauseIfRequested();
void StopIfRequested();
bool CheckIfRequestedStop();
void Pause();
void Resume(bool resumeThreadPausedById = false);
bool Pause(string id);
bool Resume(string id);
void Cancel();
bool Cancel(string id);
ExcuteResult<TResult>
Properties
// Work id.
string ID; // Get
// Result of the work.
TResult Result; // Get
// Succeed or failed.
Status Status; // Get
// If failed, Exception will be setted here.
Exception Exception; // Get
Status
enum Status { Succeed, Failed }
ThreadPoolOption
Properties
// The maximum number of threads that the thread pool can support.
int MaxThreads; // Get, Set
// The option for destroying threads in the thread pool.
DestroyThreadOption DestroyThreadOption; // Get, Set
// The total maximum amount of time that all threads in the thread pool are permitted to run collectively before they are terminated.
TimeoutOption Timeout; // Get, Set
// The default maximum amount of time a thread in the pool is allowed to run before it is terminated.
TimeoutOption DefaultThreadTimeout; // Get, Set
// The default callback function that is called when a thread finishes execution.
Action<ExecuteResult<object>> DefaultCallback; // Get, Set
DestroyThreadOption
Properties
// The amount of time a thread is kept alive after it finishes execution. If a new task is received within this time, the thread is reused; otherwise, it is destroyed.
int KeepAliveTime; // Get, Set
// The minimum number of threads that the thread pool should maintain at all times.
int MinThreads; // Get, Set
ThreadOption
Properties
// The custom work ID. If set to null, the thread pool will use a Guid as the work ID.
string CustomWorkID; // Get, Set
// The maximum amount of time the thread is allowed to run before it is terminated.
TimeoutOption Timeout; // Get, Set
// The callback function that is called when the thread finishes execution.
Action<ExecuteResult<TResult>> Callback; // Get, Set
// The priority level of the thread. Higher priority threads are executed before lower priority threads.
int Priority; // Get, Set
// A set of threads that this thread depends on. This thread will not start until all dependent threads have completed execution.
HashSet<string> Dependents; // Get, Set
TimeoutOption
Properties
// The maximum amount of time (ms)
int Duration;
// If forceStop is true, Thread.Interrupt() and Thread.Join() will be called.
bool ForceStop;
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Framework | net46 is compatible. net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 is compatible. net48 is compatible. net481 was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.6
- No dependencies.
-
.NETFramework 4.6.1
- No dependencies.
-
.NETFramework 4.7.2
- No dependencies.
-
.NETFramework 4.8
- No dependencies.
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
4.13.0 | 76 | 11/14/2024 | |
4.12.1 | 87 | 11/9/2024 | |
4.12.0 | 126 | 10/16/2024 | |
4.11.1 | 107 | 9/29/2024 | |
4.11.0 | 95 | 9/24/2024 | |
4.10.0 | 121 | 9/18/2024 | |
4.9.1 | 138 | 9/1/2024 | |
4.9.0 | 131 | 8/24/2024 | |
4.8.2 | 114 | 8/18/2024 | |
4.8.1 | 93 | 7/27/2024 | |
4.8.0 | 136 | 7/21/2024 | |
4.7.0 | 118 | 7/18/2024 | |
4.6.0 | 104 | 6/30/2024 | |
4.5.1 | 132 | 5/29/2024 | |
4.5.0 | 121 | 5/24/2024 | |
4.4.0 | 91 | 5/20/2024 | |
4.3.0 | 103 | 5/16/2024 | |
4.2.0 | 104 | 5/13/2024 | |
4.1.0 | 108 | 5/11/2024 | |
4.0.4 | 118 | 5/9/2024 | |
4.0.3 | 141 | 5/5/2024 | |
4.0.2 | 122 | 5/4/2024 | |
4.0.1 | 101 | 4/27/2024 | |
4.0.0 | 114 | 4/24/2024 | |
3.2.0 | 117 | 4/22/2024 | |
3.1.0 | 118 | 4/20/2024 | |
3.0.0 | 98 | 4/18/2024 | |
2.5.11 | 118 | 4/15/2024 | |
2.5.10 | 109 | 4/12/2024 | |
2.5.9 | 111 | 4/8/2024 | |
2.5.8 | 140 | 3/26/2024 | |
2.5.7 | 129 | 3/22/2024 | |
2.5.6 | 127 | 3/12/2024 | |
2.5.5 | 158 | 3/2/2024 | |
2.5.4 | 112 | 2/29/2024 | |
2.5.3 | 126 | 2/29/2024 | |
2.5.2 | 137 | 2/26/2024 | |
2.5.1 | 122 | 2/25/2024 | |
2.5.0 | 151 | 2/8/2024 | |
2.4.0 | 217 | 12/5/2023 | |
2.3.0 | 115 | 12/5/2023 | |
2.2.3 | 128 | 12/4/2023 | |
2.2.2 | 117 | 12/3/2023 | |
2.2.1 | 154 | 11/21/2023 | |
2.2.0 | 121 | 11/12/2023 | |
2.1.4 | 100 | 11/11/2023 | |
2.1.3 | 103 | 11/11/2023 | |
2.1.2 | 111 | 11/11/2023 | |
2.1.1 | 112 | 11/6/2023 | |
2.1.0 | 107 | 11/5/2023 | |
2.0.1 | 141 | 10/23/2023 | |
2.0.0 | 134 | 10/22/2023 | |
1.5.10 | 142 | 9/24/2023 | |
1.5.9 | 135 | 9/24/2023 | |
1.5.8 | 122 | 9/18/2023 | |
1.5.7 | 109 | 9/17/2023 | |
1.5.6 | 134 | 9/8/2023 | |
1.5.5 | 131 | 9/7/2023 | |
1.5.4 | 141 | 9/6/2023 | |
1.5.3 | 144 | 9/5/2023 | |
1.5.2 | 124 | 9/4/2023 | |
1.5.1 | 143 | 9/3/2023 | |
1.5.0 | 143 | 9/2/2023 | |
1.4.5 | 148 | 9/1/2023 | |
1.4.4 | 131 | 9/1/2023 | |
1.4.3 | 128 | 8/31/2023 | |
1.4.2 | 132 | 8/30/2023 | |
1.4.1 | 211 | 8/30/2023 | |
1.4.0 | 165 | 8/30/2023 | |
1.3.2 | 158 | 8/29/2023 | |
1.3.1 | 147 | 8/28/2023 | |
1.3.0 | 156 | 8/28/2023 | |
1.2.1 | 152 | 8/28/2023 | |
1.2.0 | 149 | 8/27/2023 | |
1.1.0 | 162 | 8/27/2023 | |
1.0.2 | 147 | 8/26/2023 | |
1.0.1 | 147 | 8/26/2023 | |
1.0.0 | 145 | 8/26/2023 |