DispatcherExtensions.SwitchToUiAwaitable Struct

An awaitable that switches execution to the UI thread.

public readonly struct SwitchToUiAwaitable : INotifyCompletion

Remarks

Instances must be obtained from DispatcherExtensions.SwitchToDispatcherThread. A default-initialized value has no dispatcher to switch to and throws InvalidOperationException when awaited.

Implements

Properties

NameDescription
IsCompletedGets a value indicating whether the awaiter has completed.

Gets a value indicating whether the awaiter has completed.

public bool IsCompleted { get; }

Property value

bool

Exceptions

InvalidOperationException
The instance was default-initialized instead of being obtained from DispatcherExtensions.SwitchToDispatcherThread.

Methods

NameDescription
GetAwaiter()Gets the awaiter for this awaitable.
GetResult()Ends the await operation.
OnCompleted(Action)Schedules the continuation action to run on the dispatcher thread.

Gets the awaiter for this awaitable.

Ends the await operation.

public void GetResult()

OnCompleted(Action)

DispatcherExtensions.cs

Schedules the continuation action to run on the dispatcher thread.

public void OnCompleted(Action continuation)

Parameters

continuation Action
The continuation action.

Exceptions

InvalidOperationException
The instance was default-initialized instead of being obtained from DispatcherExtensions.SwitchToDispatcherThread, or the dispatcher has already shut down.