Dispatcher.InvokeAsync Method

Definition

Executes the specified delegate asynchronously on the thread the Dispatcher is associated with.

Overloads

InvokeAsync(Action)

Executes the specified Action asynchronously on the thread the Dispatcher is associated with.

InvokeAsync(Action, DispatcherPriority)

Executes the specified Action asynchronously at the specified priority on the thread the Dispatcher is associated with.

InvokeAsync(Action, DispatcherPriority, CancellationToken)

Executes the specified Action asynchronously at the specified priority on the thread the Dispatcher is associated with.

InvokeAsync<TResult>(Func<TResult>, DispatcherPriority, CancellationToken)

Executes the specified Func<TResult> asynchronously at the specified priority on the thread the Dispatcher is associated with.

InvokeAsync<TResult>(Func<TResult>)

Executes the specified Func<TResult> asynchronously on the thread the Dispatcher is associated with.

InvokeAsync<TResult>(Func<TResult>, DispatcherPriority)

Executes the specified Func<TResult> asynchronously at the specified priority on the thread the Dispatcher is associated with.

InvokeAsync(Action)

Executes the specified Action asynchronously on the thread the Dispatcher is associated with.

C#
public System.Windows.Threading.DispatcherOperation InvokeAsync(Action callback);

Parameters

callback
Action

A delegate to invoke through the dispatcher.

Returns

An object, which is returned immediately after InvokeAsync(Action) is called, that can be used to interact with the delegate as it is pending execution in the event queue.

Remarks

The default priority is DispatcherPriority.Normal.

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by Invoke(Action).

Applies to

.NET Framework 4.8.1 a ďalšie verzie
Produkt Verzie
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

InvokeAsync(Action, DispatcherPriority)

Executes the specified Action asynchronously at the specified priority on the thread the Dispatcher is associated with.

C#
public System.Windows.Threading.DispatcherOperation InvokeAsync(Action callback, System.Windows.Threading.DispatcherPriority priority);

Parameters

callback
Action

A delegate to invoke through the dispatcher.

priority
DispatcherPriority

The priority that determines the order in which the specified callback is invoked relative to the other pending operations in the Dispatcher.

Returns

An object, which is returned immediately after InvokeAsync(Action, DispatcherPriority) is called, that can be used to interact with the delegate as it is pending execution in the event queue.

Remarks

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by Invoke(Action, DispatcherPriority).

Applies to

.NET Framework 4.8.1 a ďalšie verzie
Produkt Verzie
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

InvokeAsync(Action, DispatcherPriority, CancellationToken)

Executes the specified Action asynchronously at the specified priority on the thread the Dispatcher is associated with.

C#
public System.Windows.Threading.DispatcherOperation InvokeAsync(Action callback, System.Windows.Threading.DispatcherPriority priority, System.Threading.CancellationToken cancellationToken);

Parameters

callback
Action

A delegate to invoke through the dispatcher.

priority
DispatcherPriority

The priority that determines the order in which the specified callback is invoked relative to the other pending operations in the Dispatcher.

cancellationToken
CancellationToken

An object that indicates whether to cancel the action.

Returns

An object, which is returned immediately after InvokeAsync(Action, DispatcherPriority, CancellationToken) is called, that can be used to interact with the delegate as it is pending execution in the event queue.

Exceptions

The cancellation token was canceled. This exception is stored into the returned task.

Remarks

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by Invoke(Action, DispatcherPriority).

Applies to

.NET Framework 4.8.1 a ďalšie verzie
Produkt Verzie
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

InvokeAsync<TResult>(Func<TResult>, DispatcherPriority, CancellationToken)

Executes the specified Func<TResult> asynchronously at the specified priority on the thread the Dispatcher is associated with.

C#
public System.Windows.Threading.DispatcherOperation<TResult> InvokeAsync<TResult>(Func<TResult> callback, System.Windows.Threading.DispatcherPriority priority, System.Threading.CancellationToken cancellationToken);

Type Parameters

TResult

The return value type of the specified delegate.

Parameters

callback
Func<TResult>

A delegate to invoke through the dispatcher.

priority
DispatcherPriority

The priority that determines the order in which the specified callback is invoked relative to the other pending operations in the Dispatcher.

cancellationToken
CancellationToken

An object that indicates whether to cancel the operation.

Returns

An object, which is returned immediately after InvokeAsync<TResult>(Func<TResult>, DispatcherPriority, CancellationToken) is called, that can be used to interact with the delegate as it is pending execution in the event queue.

Exceptions

The cancellation token was canceled. This exception is stored into the returned task.

Applies to

.NET Framework 4.8.1 a ďalšie verzie
Produkt Verzie
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

InvokeAsync<TResult>(Func<TResult>)

Executes the specified Func<TResult> asynchronously on the thread the Dispatcher is associated with.

C#
public System.Windows.Threading.DispatcherOperation<TResult> InvokeAsync<TResult>(Func<TResult> callback);

Type Parameters

TResult

The return value type of the specified delegate.

Parameters

callback
Func<TResult>

A delegate to invoke through the dispatcher.

Returns

An object, which is returned immediately after InvokeAsync<TResult>(Func<TResult>) is called, that can be used to interact with the delegate as it is pending execution in the event queue.

Applies to

.NET Framework 4.8.1 a ďalšie verzie
Produkt Verzie
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

InvokeAsync<TResult>(Func<TResult>, DispatcherPriority)

Executes the specified Func<TResult> asynchronously at the specified priority on the thread the Dispatcher is associated with.

C#
public System.Windows.Threading.DispatcherOperation<TResult> InvokeAsync<TResult>(Func<TResult> callback, System.Windows.Threading.DispatcherPriority priority);

Type Parameters

TResult

The return value type of the specified delegate.

Parameters

callback
Func<TResult>

A delegate to invoke through the dispatcher.

priority
DispatcherPriority

The priority that determines the order in which the specified callback is invoked relative to the other pending operations in the Dispatcher.

Returns

An object, which is returned immediately after InvokeAsync<TResult>(Func<TResult>, DispatcherPriority) is called, that can be used to interact with the delegate as it is pending execution in the event queue.

Applies to

.NET Framework 4.8.1 a ďalšie verzie
Produkt Verzie
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10