Class TaskExtensions
- Namespace
- Cuemon.Extensions.Threading.Tasks
- Assembly
- Cuemon.Extensions.Threading.dll
Extension methods for the Task class.
public static class TaskExtensions
- Inheritance
-
TaskExtensions
Examples
The following example demonstrates how to await a task with or without flowing the captured synchronization context.
using System;
using System.Threading.Tasks;
using Cuemon.Extensions.Threading.Tasks;
namespace MyApp.Examples
{
public static class TaskExtensionsExample
{
public static async Task DemonstrateAsync()
{
await Task.Delay(10).ContinueWithCapturedContext();
await Task.Delay(10).ContinueWithSuppressedContext();
var captured = await Task.FromResult(42).ContinueWithCapturedContext();
var suppressed = await Task.FromResult(42).ContinueWithSuppressedContext();
Console.WriteLine(captured);
Console.WriteLine(suppressed);
}
}
}
Methods
ContinueWithCapturedContext(Task)
Configures an awaiter to marshal the continuation back to the captured synchronization context.
public static ConfiguredTaskAwaitable ContinueWithCapturedContext(this Task task)
Parameters
Returns
- ConfiguredTaskAwaitable
An object used to await this task.
ContinueWithCapturedContext<TResult>(Task<TResult>)
Configures an awaiter to marshal the continuation back to the captured synchronization context.
public static ConfiguredTaskAwaitable<TResult> ContinueWithCapturedContext<TResult>(this Task<TResult> task)
Parameters
Returns
- ConfiguredTaskAwaitable<TResult>
An object used to await this task.
Type Parameters
TResultThe type of the result produced by this Task<TResult>.
ContinueWithSuppressedContext(Task)
Configures an awaiter to suppress capturing a synchronization context back to the continuation.
public static ConfiguredTaskAwaitable ContinueWithSuppressedContext(this Task task)
Parameters
Returns
- ConfiguredTaskAwaitable
An object used to await this task.
ContinueWithSuppressedContext<TResult>(Task<TResult>)
Configures an awaiter to suppress capturing a synchronization context back to the continuation.
public static ConfiguredTaskAwaitable<TResult> ContinueWithSuppressedContext<TResult>(this Task<TResult> task)
Parameters
Returns
- ConfiguredTaskAwaitable<TResult>
An object used to await this task.
Type Parameters
TResultThe type of the result produced by this Task<TResult>.