ThrowIfCancellationRequested Method

Task Parallel System.Threading

Throws a OperationCanceledException if this token has had cancellation requested.

Namespace:  System.Threading
Assembly:  System.Threading (in System.Threading.dll)

Syntax

Visual Basic (Declaration)
Public Sub ThrowIfCancellationRequested
C#
public void ThrowIfCancellationRequested()

Remarks

This method provides functionality equivalent to:
 Copy Code
            if (token.IsCancellationRequested) 
               throw new OperationCanceledException(token);
            

Exceptions

ExceptionCondition
System..::.OperationCanceledExceptionThe token has had cancellation requested.
System..::.ObjectDisposedExceptionThe associated CancellationTokenSource has been disposed.

See Also