Class Synchronization
Represents task synchronization and combination methods.
Namespace: DotNext.Threading.Tasks
Assembly: DotNext.dll
Syntax
public static class Synchronization : object
  Methods
| Improve this Doc View SourceGetResult<R>(Task<R>, CancellationToken)
Gets task result synchronously.
Declaration
public static Result<R> GetResult<R>(this Task<R> task, CancellationToken token)
  Parameters
| Type | Name | Description | 
|---|---|---|
| Task<R> | task | The task to synchronize.  | 
      
| CancellationToken | token | Cancellation token.  | 
      
Returns
| Type | Description | 
|---|---|
| Result<R> | Task result.  | 
      
Type Parameters
| Name | Description | 
|---|---|
| R | Type of task result.  | 
      
GetResult<R>(Task<R>, TimeSpan)
Gets task result synchronously.
Declaration
public static Result<R> GetResult<R>(this Task<R> task, TimeSpan timeout)
  Parameters
| Type | Name | Description | 
|---|---|---|
| Task<R> | task | The task to synchronize.  | 
      
| TimeSpan | timeout | Synchronization timeout.  | 
      
Returns
| Type | Description | 
|---|---|
| Result<R> | Task result.  | 
      
Type Parameters
| Name | Description | 
|---|---|
| R | Type of task result.  | 
      
WaitAsync(Task, TimeSpan, CancellationToken)
Waits for task completion asynchronously.
Declaration
public static Task<bool> WaitAsync(this Task task, TimeSpan timeout, CancellationToken token = null)
  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.  | 
      
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.  |