Class TaskExtensions
Extends Task type.
Inherited Members
Namespace: DotNext.Threading
Assembly: DotNext.dll
Syntax
public static class TaskExtensions
Methods
View SourceRun<T>(Func<T, Task>, T)
Queues the specified work to run on the thread pool and returns a proxy for the task returned by function.
Declaration
public static Task Run<T>(Func<T, Task> func, T arg)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<T, Task> | func | The work to execute asynchronously. |
| T | arg | The argument to be passed to the function. |
Returns
| Type | Description |
|---|---|
| Task | A task that represents a proxy for the task returned by function. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the argument to be passed to the function. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
Run<TWorkItem>(TWorkItem)
Queues the specified work to run on the thread pool and returns a proxy for the task returned by function.
Declaration
public static Task Run<TWorkItem>(TWorkItem workItem) where TWorkItem : notnull, ISupplier<Task>
Parameters
| Type | Name | Description |
|---|---|---|
| TWorkItem | workItem | The work to execute asynchronously. |
Returns
| Type | Description |
|---|---|
| Task | A task that represents a proxy for the task returned by function. |
Type Parameters
| Name | Description |
|---|---|
| TWorkItem | The type of the work to execute asynchronously. |
Run<T, TResult>(Func<T, Task<TResult>>, T)
Queues the specified work to run on the thread pool and returns a proxy for the task returned by function.
Declaration
public static Task<TResult> Run<T, TResult>(Func<T, Task<TResult>> func, T arg)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<T, Task<TResult>> | func | The work to execute asynchronously. |
| T | arg | The argument to be passed to the function. |
Returns
| Type | Description |
|---|---|
| Task<TResult> | A task that represents a proxy for the task returned by function. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the argument to be passed to the function. |
| TResult | The result of the function. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
Run<T1, T2>(Func<T1, T2, Task>, T1, T2)
Queues the specified work to run on the thread pool and returns a proxy for the task returned by function.
Declaration
public static Task Run<T1, T2>(Func<T1, T2, Task> func, T1 arg1, T2 arg2)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<T1, T2, Task> | func | The work to execute asynchronously. |
| T1 | arg1 | The first argument to be passed to the function. |
| T2 | arg2 | The second argument to be passed to the function. |
Returns
| Type | Description |
|---|---|
| Task | A task that represents a proxy for the task returned by function. |
Type Parameters
| Name | Description |
|---|---|
| T1 | The type of the first argument to be passed to the function. |
| T2 | The type of the second argument to be passed to the function. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
Run<TResult, TWorkItem>(TWorkItem)
Queues the specified work to run on the thread pool and returns a proxy for the task returned by function.
Declaration
public static Task<TResult> Run<TResult, TWorkItem>(TWorkItem workItem) where TResult : notnull where TWorkItem : notnull, ISupplier<Task<TResult>>
Parameters
| Type | Name | Description |
|---|---|---|
| TWorkItem | workItem | The work to execute asynchronously. |
Returns
| Type | Description |
|---|---|
| Task<TResult> | A task that represents a proxy for the task returned by function. |
Type Parameters
| Name | Description |
|---|---|
| TResult | The result of the function. |
| TWorkItem | The type of the work to execute asynchronously. |
Run<T1, T2, TResult>(Func<T1, T2, Task<TResult>>, T1, T2)
Queues the specified work to run on the thread pool and returns a proxy for the task returned by function.
Declaration
public static Task<TResult> Run<T1, T2, TResult>(Func<T1, T2, Task<TResult>> func, T1 arg1, T2 arg2)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<T1, T2, Task<TResult>> | func | The work to execute asynchronously. |
| T1 | arg1 | The first argument to be passed to the function. |
| T2 | arg2 | The second argument to be passed to the function. |
Returns
| Type | Description |
|---|---|
| Task<TResult> | A task that represents a proxy for the task returned by function. |
Type Parameters
| Name | Description |
|---|---|
| T1 | The type of the first argument to be passed to the function. |
| T2 | The type of the second argument to be passed to the function. |
| TResult | The result of the function. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
Run<T1, T2, T3>(Func<T1, T2, T3, Task>, T1, T2, T3)
Queues the specified work to run on the thread pool and returns a proxy for the task returned by function.
Declaration
public static Task Run<T1, T2, T3>(Func<T1, T2, T3, Task> func, T1 arg1, T2 arg2, T3 arg3)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<T1, T2, T3, Task> | func | The work to execute asynchronously. |
| T1 | arg1 | The first argument to be passed to the function. |
| T2 | arg2 | The second argument to be passed to the function. |
| T3 | arg3 | The third argument to be passed to the function. |
Returns
| Type | Description |
|---|---|
| Task | A task that represents a proxy for the task returned by function. |
Type Parameters
| Name | Description |
|---|---|
| T1 | The type of the first argument to be passed to the function. |
| T2 | The type of the second argument to be passed to the function. |
| T3 | The type of the third argument to be passed to the function. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
Run<T1, T2, T3, TResult>(Func<T1, T2, T3, Task<TResult>>, T1, T2, T3)
Queues the specified work to run on the thread pool and returns a proxy for the task returned by function.
Declaration
public static Task<TResult> Run<T1, T2, T3, TResult>(Func<T1, T2, T3, Task<TResult>> func, T1 arg1, T2 arg2, T3 arg3)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<T1, T2, T3, Task<TResult>> | func | The work to execute asynchronously. |
| T1 | arg1 | The first argument to be passed to the function. |
| T2 | arg2 | The second argument to be passed to the function. |
| T3 | arg3 | The third argument to be passed to the function. |
Returns
| Type | Description |
|---|---|
| Task<TResult> | A task that represents a proxy for the task returned by function. |
Type Parameters
| Name | Description |
|---|---|
| T1 | The type of the first argument to be passed to the function. |
| T2 | The type of the second argument to be passed to the function. |
| T3 | The type of the third argument to be passed to the function. |
| TResult | The result of the function. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
Run<T1, T2, T3, T4>(Func<T1, T2, T3, T4, Task>, T1, T2, T3, T4)
Queues the specified work to run on the thread pool and returns a proxy for the task returned by function.
Declaration
public static Task Run<T1, T2, T3, T4>(Func<T1, T2, T3, T4, Task> func, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<T1, T2, T3, T4, Task> | func | The work to execute asynchronously. |
| T1 | arg1 | The first argument to be passed to the function. |
| T2 | arg2 | The second argument to be passed to the function. |
| T3 | arg3 | The third argument to be passed to the function. |
| T4 | arg4 | The fourth argument to be passed to the function. |
Returns
| Type | Description |
|---|---|
| Task | A task that represents a proxy for the task returned by function. |
Type Parameters
| Name | Description |
|---|---|
| T1 | The type of the first argument to be passed to the function. |
| T2 | The type of the second argument to be passed to the function. |
| T3 | The type of the third argument to be passed to the function. |
| T4 | The type of the fourth argument to be passed to the function. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
Run<T1, T2, T3, T4, TResult>(Func<T1, T2, T3, T4, Task<TResult>>, T1, T2, T3, T4)
Queues the specified work to run on the thread pool and returns a proxy for the task returned by function.
Declaration
public static Task<TResult> Run<T1, T2, T3, T4, TResult>(Func<T1, T2, T3, T4, Task<TResult>> func, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<T1, T2, T3, T4, Task<TResult>> | func | The work to execute asynchronously. |
| T1 | arg1 | The first argument to be passed to the function. |
| T2 | arg2 | The second argument to be passed to the function. |
| T3 | arg3 | The third argument to be passed to the function. |
| T4 | arg4 | The fourth argument to be passed to the function. |
Returns
| Type | Description |
|---|---|
| Task<TResult> | A task that represents a proxy for the task returned by function. |
Type Parameters
| Name | Description |
|---|---|
| T1 | The type of the first argument to be passed to the function. |
| T2 | The type of the second argument to be passed to the function. |
| T3 | The type of the third argument to be passed to the function. |
| T4 | The type of the fourth argument to be passed to the function. |
| TResult | The result of the function. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
YieldToThreadPool()
Yields control to the caller and resumes the asynchronous method on ThreadPool.
Declaration
public static ConfiguredTaskAwaitable YieldToThreadPool()
Returns
| Type | Description |
|---|---|
| ConfiguredTaskAwaitable | The awaitable object that resumes the caller on the thread pool. |
Remarks
In contrast to Yield(), the continuation ignores the current SynchronizationContext and TaskScheduler. For instance, awaiting this method inside a task scheduled by ExclusiveScheduler leaves the exclusive scheduler. The method always yields, even if the caller is already running on the thread pool.