SynchronizationContextExtensions.SynchronizationContextAwaiter Struct

Awaits a SynchronizationContext, resuming the awaiting method on that context.

public readonly struct SynchronizationContextAwaiter : ICriticalNotifyCompletion, INotifyCompletion
Implements

Constructors

NameDescription
SynchronizationContextAwaiter(SynchronizationContext)Awaits a SynchronizationContext, resuming the awaiting method on that context.

SynchronizationContextAwaiter(SynchronizationContext)

Awaits a SynchronizationContext, resuming the awaiting method on that context.

public SynchronizationContextAwaiter(SynchronizationContext synchronizationContext)

Parameters

synchronizationContext SynchronizationContext
The synchronization context to resume on.

Properties

NameDescription
IsCompletedGets a value indicating whether the current synchronization context is the awaited one, in which case the awaiting method continues synchronously.

Gets a value indicating whether the current synchronization context is the awaited one, in which case the awaiting method continues synchronously.

public bool IsCompleted { get; }

Property value

bool

Remarks

The synchronization contexts are compared by instance. A different instance bound to the same thread, such as the ones WPF installs while running a dispatcher operation, is not recognized: the continuation is then posted, which is still correct but does not complete synchronously.

Methods

NameDescription
GetResult()Ends the await. This method does nothing.
OnCompleted(Action)Posts continuation to the synchronization context.
UnsafeOnCompleted(Action)Posts continuation to the synchronization context.

Ends the await. This method does nothing.

public void GetResult()

Posts continuation to the synchronization context.

public void OnCompleted(Action continuation)

Parameters

continuation Action
The action to invoke once the awaiting method resumes.

UnsafeOnCompleted(Action)

SynchronizationContextExtensions.cs

Posts continuation to the synchronization context.

public void UnsafeOnCompleted(Action continuation)

Parameters

continuation Action
The action to invoke once the awaiting method resumes.

Remarks

The async method builders call this method and flow the ExecutionContext themselves.