Class TaskExtensions
Collection of extension methods for Task.
Namespace: Microsoft.MixedReality.WebRTC
Assembly: Microsoft.MixedReality.WebRTC.dll
Syntax
public static class TaskExtensions : object
Methods
| Improve this Doc View SourceAsTask(CancellationToken)
A simple helper to enable "awaiting" a
Declaration
public static Task AsTask(this CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
Task | The task that can be awaited. |
IgnoreCancellation(Task)
Prevents
Declaration
public static Task IgnoreCancellation(this Task task)
Parameters
Type | Name | Description |
---|---|---|
Task | task | The task to ignore exceptions for. |
Returns
Type | Description |
---|---|
Task | A wrapping task for the given task. |
IgnoreCancellation<T>(Task<T>, T)
Prevents
Declaration
public static Task<T> IgnoreCancellation<T>(this Task<T> task, T defaultCancellationReturn = null)
Parameters
Type | Name | Description |
---|---|---|
Task<T> | task | The task to ignore exceptions for. |
T | defaultCancellationReturn | The default value to return in case the task is cancelled. |
Returns
Type | Description |
---|---|
Task<T> | A wrapping task for the given task. |
Type Parameters
Name | Description |
---|---|
T | The result type of the Task. |
Unless(Task, CancellationToken)
The task will be awaited until the cancellation token is triggered. (await task unless cancelled).
Declaration
public static Task Unless(this Task task, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
Task | task | The task to await. |
CancellationToken | cancellationToken | The cancellation token to stop awaiting. |
Returns
Type | Description |
---|---|
Task | The task that can be awaited unless the cancellation token is triggered. |
Remarks
This is different from cancelling the task. The use case is to enable a calling method bow out of the await that it can't cancel, but doesn't require completion/cancellation in order to cancel it's own execution.