CancellationTokenSource Class

May 11, 2014

Signals to a CancellationToken that it should be canceled.

System.Object
  System.Threading.CancellationTokenSource

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

public class CancellationTokenSource : IDisposable

The CancellationTokenSource type exposes the following members.

  NameDescription
Public methodCancellationTokenSource()Initializes the CancellationTokenSource.
Public methodCancellationTokenSource(Int32)Constructs a CancellationTokenSource that will be canceled after a specified time span.
Public methodCancellationTokenSource(TimeSpan)Constructs a CancellationTokenSource that will be canceled after a specified time span.
Top

  NameDescription
Public propertyIsCancellationRequestedGets whether cancellation has been requested for this CancellationTokenSource.
Public propertyTokenGets the CancellationToken associated with this CancellationTokenSource.
Top

  NameDescription
Public methodCancel()Communicates a request for cancellation.
Public methodCancel(Boolean)Communicates a request for cancellation.
Public methodCancelAfter(Int32)Schedules a Cancel operation on this CancellationTokenSource.
Public methodCancelAfter(TimeSpan)Schedules a Cancel operation on this CancellationTokenSource.
Public methodStatic memberCreateLinkedTokenSource(CancellationToken[])Creates a CancellationTokenSource that will be in the canceled state when any of the source tokens are in the canceled state.
Public methodStatic memberCreateLinkedTokenSource(CancellationToken, CancellationToken)Creates a CancellationTokenSource that will be in the canceled state when any of the source tokens are in the canceled state.
Public methodDispose()Releases all resources used by the current instance of the CancellationTokenSource class.
Protected methodDispose(Boolean)Releases the unmanaged resources used by the CancellationTokenSource class and optionally releases the managed resources.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

For more information and code examples see [eea11fe5-d8b0-4314-bb5d-8a58166fb1c3].

Windows Phone OS

Supported in: 8.1, 8.0

All public and protected members of CancellationTokenRegistration 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 CancellationTokenRegistration have completed.

Show:
© 2014 Microsoft