Signals to a CancellationToken that it should be canceled.
Assembly: mscorlib (in mscorlib.dll)
Thetype exposes the following members.
|CancellationTokenSource()||Initializes a new instance of the class.|
|CancellationTokenSource(Int32)||Initializes a new instance of the class that will be canceled after the specified delay in milliseconds.|
|CancellationTokenSource(TimeSpan)||Initializes a new instance of the class that will be canceled after the specified time span.|
|Cancel()||Communicates a request for cancellation.|
|Cancel(Boolean)||Communicates a request for cancellation, and specifies whether remaining callbacks and cancelable operations should be processed.|
|CancelAfter(Int32)||Schedules a cancel operation on this after the specified number of milliseconds.|
|CancelAfter(TimeSpan)||Schedules a cancel operation on this after the specified time span.|
|CreateLinkedTokenSource(CancellationToken)||Creates a that will be in the canceled state when any of the source tokens in the specified array are in the canceled state.|
|CreateLinkedTokenSource(CancellationToken, CancellationToken)||Creates a that will be in the canceled state when any of the source tokens are in the canceled state.|
|Dispose()||Releases all resources used by the current instance of the class.|
|Dispose(Boolean)||Releases the unmanaged resources used by the class and optionally releases the managed resources.|
|Equals(Object)||Determines whether the specified object is equal to the current object. (Inherited from Object.)|
|Finalize||Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)|
|GetHashCode||Serves as the default hash function. (Inherited from Object.)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|MemberwiseClone||Creates a shallow copy of the current Object. (Inherited from Object.)|
|ToString||Returns a string that represents the current object. (Inherited from Object.)|
For more information, see Cancellation in Managed Threads.
The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: Synchronization | ExternalThreading. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.
The following example uses a random number generator to emulate a data collection application that reads 10 integral values from eleven different instruments. A value of zero indicates that the measurement has failed for one instrument, in which case the operation should be cancelled and no overall mean should be computed.
To handle the possible cancellation of the operation, the example instantiates a object that generates a cancellation token which is passed to a TaskFactory object. The TaskFactory object in turn passes the cancellation token to each of the tasks responsible for collecting readings for a particular instrument. The TaskFactory.ContinueWhenAll(TAntecedentResult, TResult)(Task(TAntecedentResult), Func(Task(TAntecedentResult), TResult), CancellationToken) method is called to ensure that the mean is computed only after all readings have been gathered successfully. If a task has not because it has been cancelled, the call to the TaskFactory.ContinueWhenAll method throws an exception.
Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
All public and protected members of 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 object have completed.