Class TaskExtensions
Extensions for the Task class.
Inherited Members
Namespace: TheXDS.MCART.Types.Extensions
Assembly: MCART.dll
Syntax
public static class TaskExtensions
Methods
| Edit this page View SourceEnqueue<T>(T, ICollection<Task>)
Queues a task.
Declaration
public static T Enqueue<T>(this T task, ICollection<Task> tasks) where T : Task
Parameters
Type | Name | Description |
---|---|---|
T | task | Task to add to the queue. |
ICollection<Task> | tasks | Queue of tasks. |
Returns
Type | Description |
---|---|
T |
|
Type Parameters
Name | Description |
---|---|
T | Type of the task. |
WithCancellation(Task, CancellationToken)
Adds cancellation support to tasks that do not natively support using a CancellationToken.
Declaration
public static Task WithCancellation(this Task task, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
Task | task | Task to execute. |
CancellationToken | cancellationToken | Cancellation token. |
Returns
Type | Description |
---|---|
Task | The result of the asynchronous operation. |
Exceptions
Type | Condition |
---|---|
TaskCanceledException | Thrown when the task is canceled using
|
WithCancellation<T>(Task<T>, CancellationToken)
Adds cancellation support to tasks that do not natively support using a CancellationToken.
Declaration
public static Task<T> WithCancellation<T>(this Task<T> task, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
Task<T> | task | Task to execute. |
CancellationToken | cancellationToken | Cancellation token. |
Returns
Type | Description |
---|---|
Task<T> | The result of the asynchronous operation. |
Type Parameters
Name | Description |
---|---|
T | Type of result returned by the task. |
Exceptions
Type | Condition |
---|---|
TaskCanceledException | Thrown when the task is canceled using
|
Yield<T>(Task<T>)
Waits for a task to complete and returns its result.
Declaration
public static T Yield<T>(this Task<T> task)
Parameters
Type | Name | Description |
---|---|---|
Task<T> | task | Task to wait for. |
Returns
Type | Description |
---|---|
T | The result of the Task<TResult>. |
Type Parameters
Name | Description |
---|---|
T | Type of result returned by the Task<TResult>. |
Yield<T>(Task<T>, int)
Waits for a task to complete and returns its result.
Declaration
public static T Yield<T>(this Task<T> task, int msTimeout)
Parameters
Type | Name | Description |
---|---|---|
Task<T> | task | Task to wait for. |
int | msTimeout | Time in milliseconds to wait for the task to complete before forcibly aborting it. |
Returns
Type | Description |
---|---|
T | The result of the Task<TResult>. |
Type Parameters
Name | Description |
---|---|
T | Type of result returned by the Task<TResult>. |
Yield<T>(Task<T>, int, CancellationToken)
Waits for a task to complete and returns its result.
Declaration
public static T Yield<T>(this Task<T> task, int msTimeout, CancellationToken ct)
Parameters
Type | Name | Description |
---|---|---|
Task<T> | task | Task to wait for. |
int | msTimeout | Time in milliseconds to wait for the task to complete before forcibly aborting it. |
CancellationToken | ct | Cancellation token for the task. |
Returns
Type | Description |
---|---|
T | The result of the Task<TResult>. |
Type Parameters
Name | Description |
---|---|
T | Type of result returned by the Task<TResult>. |
Yield<T>(Task<T>, CancellationToken)
Waits for a task to complete and returns its result.
Declaration
public static T Yield<T>(this Task<T> task, CancellationToken ct)
Parameters
Type | Name | Description |
---|---|---|
Task<T> | task | Task to wait for. |
CancellationToken | ct | Cancellation token for the task. |
Returns
Type | Description |
---|---|
T | The result of the Task<TResult>. |
Type Parameters
Name | Description |
---|---|
T | Type of result returned by the Task<TResult>. |
Yield<T>(Task<T>, TimeSpan)
Waits for a task to complete and returns its result.
Declaration
public static T Yield<T>(this Task<T> task, TimeSpan timeout)
Parameters
Type | Name | Description |
---|---|---|
Task<T> | task | Task to wait for. |
TimeSpan | timeout | Time span to wait for the task to complete before forcibly aborting it. |
Returns
Type | Description |
---|---|
T | The result of the Task<TResult>. |
Type Parameters
Name | Description |
---|---|
T | Type of result returned by the Task<TResult>. |