Bewerken

Delen via


CancellationTokenSource.CancelAsync Method

Definition

Communicates a request for cancellation asynchronously.

public:
 System::Threading::Tasks::Task ^ CancelAsync();
public System.Threading.Tasks.Task CancelAsync ();
member this.CancelAsync : unit -> System.Threading.Tasks.Task
Public Function CancelAsync () As Task

Returns

A task that will complete after cancelable operations and callbacks registered with the associated CancellationToken have completed.

Exceptions

Remarks

The associated CancellationToken will be notified of the cancellation and will synchronously transition to a state where IsCancellationRequested returns true. Any callbacks or cancelable operations registered with the CancellationToken will be executed asynchronously, with the returned Task representing their eventual completion.

Callbacks registered with the token should not throw exceptions. However, any such exceptions that are thrown will be aggregated into an AggregateException, such that one callback throwing an exception will not prevent other registered callbacks from being executed.

The ExecutionContext that was captured when each callback was registered will be reestablished when the callback is invoked.

Applies to