Class Synchronization
Represents task synchronization and combination methods.
Inherited Members
Namespace: DotNext.Threading.Tasks
Assembly: DotNext.dll
Syntax
public static class Synchronization
Methods
| Improve this Doc View SourceGetResult(Task, CancellationToken)
Gets task result synchronously.
Declaration
public static Result<dynamic> GetResult(this Task task, CancellationToken token)
Parameters
| Type | Name | Description |
|---|---|---|
| Task | task | The task to synchronize. |
| CancellationToken | token | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Result<Object> | Task result; or Value returned from Value if |
GetResult(Task, TimeSpan)
Gets task result synchronously.
Declaration
public static Result<dynamic> GetResult(this Task task, TimeSpan timeout)
Parameters
| Type | Name | Description |
|---|---|---|
| Task | task | The task to synchronize. |
| TimeSpan | timeout | Synchronization timeout. |
Returns
| Type | Description |
|---|---|
| Result<Object> | Task result; or Value returned from Value if |
Exceptions
| Type | Condition |
|---|---|
| TimeoutException | Task is not completed. |
GetResult<TResult>(Task<TResult>, CancellationToken)
Gets task result synchronously.
Declaration
public static Result<TResult> GetResult<TResult>(this Task<TResult> task, CancellationToken token)
Parameters
| Type | Name | Description |
|---|---|---|
| Task<TResult> | task | The task to synchronize. |
| CancellationToken | token | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Result<TResult> | Task result. |
Type Parameters
| Name | Description |
|---|---|
| TResult | Type of task result. |
GetResult<TResult>(Task<TResult>, TimeSpan)
Gets task result synchronously.
Declaration
public static Result<TResult> GetResult<TResult>(this Task<TResult> task, TimeSpan timeout)
Parameters
| Type | Name | Description |
|---|---|---|
| Task<TResult> | task | The task to synchronize. |
| TimeSpan | timeout | Synchronization timeout. |
Returns
| Type | Description |
|---|---|
| Result<TResult> | Task result. |
Type Parameters
| Name | Description |
|---|---|
| TResult | Type of task result. |
Exceptions
| Type | Condition |
|---|---|
| TimeoutException | Task is not completed. |
WaitAsync(Task, TimeSpan, CancellationToken)
Waits for task completion asynchronously.
Declaration
public static Task<bool> WaitAsync(this Task task, TimeSpan timeout, CancellationToken token = default(CancellationToken))
Parameters
| Type | Name | Description |
|---|---|---|
| Task | task | The task to await. |
| TimeSpan | timeout | The time to wait for task completion. |
| CancellationToken | token | The token that can be used to cancel awaiting. |
Returns
| Type | Description |
|---|---|
| Task<Boolean> | true if task is completed; false if task is not completed. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
| OperationCanceledException | The operation has been canceled. |
WhenAll<T1, T2>(Task<T1>, Task<T2>)
Creates a task that will complete when all of the passed tasks have completed.
Declaration
public static Task<(T1, T2)> WhenAll<T1, T2>(Task<T1> task1, Task<T2> task2)
Parameters
| Type | Name | Description |
|---|---|---|
| Task<T1> | task1 | The first task to await. |
| Task<T2> | task2 | The second task to await. |
Returns
| Type | Description |
|---|---|
| Task<ValueTuple<T1, T2>> | The task containing results of both tasks. |
Type Parameters
| Name | Description |
|---|---|
| T1 | The type of the first task. |
| T2 | The type of the second task. |
WhenAll<T1, T2, T3>(Task<T1>, Task<T2>, Task<T3>)
Creates a task that will complete when all of the passed tasks have completed.
Declaration
public static Task<(T1, T2, T3)> WhenAll<T1, T2, T3>(Task<T1> task1, Task<T2> task2, Task<T3> task3)
Parameters
| Type | Name | Description |
|---|---|---|
| Task<T1> | task1 | The first task to await. |
| Task<T2> | task2 | The second task to await. |
| Task<T3> | task3 | The third task to await. |
Returns
| Type | Description |
|---|---|
| Task<ValueTuple<T1, T2, T3>> | The task containing results of all tasks. |
Type Parameters
| Name | Description |
|---|---|
| T1 | The type of the first task. |
| T2 | The type of the second task. |
| T3 | The type of the third task. |
WhenAll<T1, T2, T3, T4>(Task<T1>, Task<T2>, Task<T3>, Task<T4>)
Creates a task that will complete when all of the passed tasks have completed.
Declaration
public static Task<(T1, T2, T3, T4)> WhenAll<T1, T2, T3, T4>(Task<T1> task1, Task<T2> task2, Task<T3> task3, Task<T4> task4)
Parameters
| Type | Name | Description |
|---|---|---|
| Task<T1> | task1 | The first task to await. |
| Task<T2> | task2 | The second task to await. |
| Task<T3> | task3 | The third task to await. |
| Task<T4> | task4 | The fourth task to await. |
Returns
| Type | Description |
|---|---|
| Task<ValueTuple<T1, T2, T3, T4>> | The task containing results of all tasks. |
Type Parameters
| Name | Description |
|---|---|
| T1 | The type of the first task. |
| T2 | The type of the second task. |
| T3 | The type of the third task. |
| T4 | The type of the fourth task. |
WhenAll<T1, T2, T3, T4, T5>(Task<T1>, Task<T2>, Task<T3>, Task<T4>, Task<T5>)
Creates a task that will complete when all of the passed tasks have completed.
Declaration
public static Task<(T1, T2, T3, T4, T5)> WhenAll<T1, T2, T3, T4, T5>(Task<T1> task1, Task<T2> task2, Task<T3> task3, Task<T4> task4, Task<T5> task5)
Parameters
| Type | Name | Description |
|---|---|---|
| Task<T1> | task1 | The first task to await. |
| Task<T2> | task2 | The second task to await. |
| Task<T3> | task3 | The third task to await. |
| Task<T4> | task4 | The fourth task to await. |
| Task<T5> | task5 | The fifth task to await. |
Returns
| Type | Description |
|---|---|
| Task<ValueTuple<T1, T2, T3, T4, T5>> | The task containing results of all tasks. |
Type Parameters
| Name | Description |
|---|---|
| T1 | The type of the first task. |
| T2 | The type of the second task. |
| T3 | The type of the third task. |
| T4 | The type of the fourth task. |
| T5 | The type of the fifth task. |