CancellationToken Structure

Propagates notification that operations should be canceled.

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

Syntax

'Declaration
<DebuggerDisplayAttribute("IsCancellationRequested = {IsCancellationRequested}")> _
<ComVisibleAttribute(False)> _
Public Structure CancellationToken
[DebuggerDisplayAttribute("IsCancellationRequested = {IsCancellationRequested}")]
[ComVisibleAttribute(false)]
public struct CancellationToken

The CancellationToken type exposes the following members.

Constructors

  Name Description
Public method CancellationToken Initializes the CancellationToken.

Top

Properties

  Name Description
Public property CanBeCanceled Gets whether this token is capable of being in the canceled state.
Public property IsCancellationRequested Gets whether cancellation has been requested for this token.
Public propertyStatic member None Returns an empty CancellationToken value.
Public property WaitHandle Gets a WaitHandle that is signaled when the token is canceled.

Top

Methods

  Name Description
Public method Equals(CancellationToken) Determines whether the current CancellationToken instance is equal to the specified token.
Public method Equals(Object) Determines whether the current CancellationToken instance is equal to the specified Object. (Overrides ValueType.Equals(Object).)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a CancellationToken. (Overrides ValueType.GetHashCode().)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method Register(Action) Registers a delegate that will be called when this CancellationToken is canceled.
Public method Register(Action, Boolean) Registers a delegate that will be called when this CancellationToken is canceled.
Public method Register(Action<Object>, Object) Registers a delegate that will be called when this CancellationToken is canceled.
Public method Register(Action<Object>, Object, Boolean) Registers a delegate that will be called when this CancellationToken is canceled.
Public method ThrowIfCancellationRequested Throws a OperationCanceledException if this token has had cancellation requested.
Public method ToString Returns the fully qualified type name of this instance. (Inherited from ValueType.)

Top

Operators

  Name Description
Public operatorStatic member Equality Determines whether two CancellationToken instances are equal.
Public operatorStatic member Inequality Determines whether two CancellationToken instances are not equal.

Top

Remarks

For more information and code examples see Cancellation.

Version Information

Silverlight

Supported in: 5

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Thread Safety

All public and protected members of CancellationToken are thread-safe and may be used concurrently from multiple threads, with the exception of Dispose, which must only be used when all other operations on the CancellationToken have completed.