CancellationTokenSource Class
Signals to a CancellationToken that it should be canceled.
Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)
The CancellationTokenSource type exposes the following members.
| Name | Description | |
|---|---|---|
![]() ![]() ![]() | CancellationTokenSource() | Initializes a new instance of the CancellationTokenSource class. |
![]() ![]() | CancellationTokenSource(Int32) | Initializes a new instance of the CancellationTokenSource class that will be canceled after the specified delay in milliseconds. |
![]() ![]() | CancellationTokenSource(TimeSpan) | Initializes a new instance of the CancellationTokenSource class that will be canceled after the specified time span. |
| Name | Description | |
|---|---|---|
![]() ![]() ![]() | IsCancellationRequested | Gets whether cancellation has been requested for this CancellationTokenSource. |
![]() ![]() ![]() | Token | Gets the CancellationToken associated with this CancellationTokenSource. |
| Name | Description | |
|---|---|---|
![]() ![]() ![]() | 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 CancellationTokenSource after the specified number of milliseconds. |
![]() ![]() | CancelAfter(TimeSpan) | Schedules a cancel operation on this CancellationTokenSource after the specified time span. |
![]() ![]() ![]() ![]() | CreateLinkedTokenSource(CancellationToken[]) | Creates a CancellationTokenSource 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 CancellationTokenSource 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 CancellationTokenSource class. |
![]() ![]() | Dispose(Boolean) | Releases the unmanaged resources used by the CancellationTokenSource 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 a hash function for a particular type. (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 and code examples see Cancellation in Managed Threads.
Note |
|---|
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. |
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 CancellationTokenSource 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 CancellationTokenSource object have completed.






Note