Skip to content

Getting Started

ZjzMisaka edited this page Sep 8, 2023 · 9 revisions

PowerThreadPool is available as Nuget Package now.

QueueWorkItem

PowerPool powerPool = new PowerPool(new PowerPoolOption() { /* Some options */ });
string id = powerPool.QueueWorkItem(() => 
{
    // DO SOMETHING
});

With callback

PowerPool powerPool = new PowerPool(new PowerPoolOption() { /* Some options */ });
powerPool.QueueWorkItem(() => 
{
    // DO SOMETHING
    return result;
}, (res) => 
{
    // Callback of the work
});

With option

PowerPool powerPool = new PowerPool(new PowerPoolOption() { /* Some options */ });
powerPool.QueueWorkItem(() => 
{
    // DO SOMETHING
    return result;
}, new WorkOption()
{
    // Some options
});

Work types

The QueueWorkItem function accepts a variety of work types, including Action and Func delegates. These delegates can be parameterized with different amounts of arguments, and can optionally include a callback function or a WorkOption object. The types of works that this thread pool API accepts are as follows:

Action<T1>
Action<T1, T2>
Action<T1, T2, T3>
Action<T1, T2, T3, T4>
Action<T1, T2, T3, T4, T5>
Action
Action<object[]>
Func<T1, TResult>
Func<T1, T2, TResult>
Func<T1, T2, T3, TResult>
Func<T1, T2, T3, T4, TResult>
Func<T1, T2, T3, T4, T5, TResult>
Func<TResult>
Func<object[], TResult>