CancellationToken.ThrowIfCancellationRequested 方法

定义

如果已请求取消此标记,则引发 OperationCanceledExceptionThrows a OperationCanceledException if this token has had cancellation requested.

public:
 void ThrowIfCancellationRequested();
public void ThrowIfCancellationRequested ();
member this.ThrowIfCancellationRequested : unit -> unit
Public Sub ThrowIfCancellationRequested ()

异常

已请求取消此标记。The token has had cancellation requested.

关联 CancellationTokenSource 已被释放。The associated CancellationTokenSource has been disposed.

注解

此方法提供等效于的功能:This method provides functionality equivalent to:

C#C#

if (token.IsCancellationRequested)   
    throw new OperationCanceledException(token);  
If token.IsCancellationRequested Then  
    Throw New OperationCanceledException(token)  
End If  

适用于

另请参阅