Task::Wait Method (CancellationToken)
Waits for the cancellable Task to complete execution.
Assembly: mscorlib (in mscorlib.dll)
The cancellationToken was canceled.
The Task has been disposed.
The Task was canceled -or- an exception was thrown during the execution of the Task. If the task was canceled, the AggregateException contains an OperationCanceledException in its InnerExceptions collection.
The following example instantiates a CancellationTokenSource object and runs a task that calls its Cancel method to request a cancellation. It runs a second task that enters a long-running loop. The Wait method is called inside a try/catch block and is passed the cancellation token (CancellationToken object) from the CancellationTokenSource object. Because cancellation was requested, the call to the Wait method throws an OperationCanceledException exception.