Table of Contents

TaskExtensions Class

Definition

Namespace
Cuemon.Extensions.Threading.Tasks
Assemblies
Cuemon.Extensions.Threading.dll
Source
src/Cuemon.Extensions.Threading/Tasks/TaskExtensions.cs

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

Name Description
ContinueWithCapturedContext(Task)

Configures an awaiter to marshal the continuation back to the captured synchronization context.

ContinueWithCapturedContext<TResult>(Task<TResult>)

Configures an awaiter to marshal the continuation back to the captured synchronization context.

ContinueWithSuppressedContext(Task)

Configures an awaiter to suppress capturing a synchronization context back to the continuation.

ContinueWithSuppressedContext<TResult>(Task<TResult>)

Configures an awaiter to suppress capturing a synchronization context back to the continuation.