Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
struct System.​Threading.​CancellationToken
Assembly: System.Runtime
Implemented Interfaces
Propagates notification that operations should be canceled.
Properties
public
bool
CanBeCanceled
Gets whether this token is capable of being in the canceled state.
public
bool
IsCancellationRequested
Gets whether cancellation has been requested for this token.
public static
CancellationToken
None
Returns an empty <see cref="T:System.Threading.CancellationToken" /> value.
public
WaitHandle
WaitHandle
Gets a <see cref="T:System.Threading.WaitHandle" /> that is signaled when the token is canceled.
Methods
public
bool
Equals​(object other)
Determines whether the current <see cref="T:System.Threading.CancellationToken" /> instance is equal to the specified <see cref="T:System.Object" /> .
Returns <see langword="true" /> if <paramref name="other" /> is a <see cref="T:System.Threading.CancellationToken" /> and if the two instances are equal; otherwise, <see langword="false" /> . See the Remarks section for more information.
other
The other object to compare with this instance.
public
bool
Equals​(CancellationToken other)
Determines whether the current <see cref="T:System.Threading.CancellationToken" /> instance is equal to the specified token.
Returns <see langword="true" /> if the instances are equal; otherwise, <see langword="false" /> . See the Remarks section for more information.
other
The other <see cref="T:System.Threading.CancellationToken" /> to compare with this instance.
public
int
GetHashCode​()
Serves as a hash function for a <see cref="T:System.Threading.CancellationToken" /> .
Returns A hash code for the current <see cref="T:System.Threading.CancellationToken" /> instance.
Register​(Action callback)
Registers a delegate that will be called when this <see cref="T:System.Threading.CancellationToken" /> is canceled.
Returns The <see cref="T:System.Threading.CancellationTokenRegistration" /> instance that can be used to unregister the callback.
callback
The delegate to be executed when the <see cref="T:System.Threading.CancellationToken" /> is canceled.
Register​(Action callback,
bool useSynchronizationContext)
Registers a delegate that will be called when this <see cref="T:System.Threading.CancellationToken" /> is canceled.
Returns The <see cref="T:System.Threading.CancellationTokenRegistration" /> instance that can be used to unregister the callback.
callback
The delegate to be executed when the <see cref="T:System.Threading.CancellationToken" /> is canceled.
useSynchronizationContext
A value that indicates whether to capture the current <see cref="T:System.Threading.SynchronizationContext" /> and use it when invoking the <paramref name="callback" /> .
Register​(Action<​object, CancellationToken> callback,
object state)
Registers a delegate that will be called when this <see cref="T:System.Threading.CancellationToken">CancellationToken</see> is canceled.
Returns The <see cref="T:System.Threading.CancellationTokenRegistration" /> instance that can be used to unregister the callback.
callback
The delegate to be executed when the <see cref="T:System.Threading.CancellationToken">CancellationToken</see> is canceled.
state
The state to pass to the <paramref name="callback" /> when the delegate is invoked. This may be <see langword="null" /> .
Register​(Action<​object> callback,
object state)
Registers a delegate that will be called when this <see cref="T:System.Threading.CancellationToken" /> is canceled.
Returns The <see cref="T:System.Threading.CancellationTokenRegistration" /> instance that can be used to unregister the callback.
callback
The delegate to be executed when the <see cref="T:System.Threading.CancellationToken" /> is canceled.
state
The state to pass to the <paramref name="callback" /> when the delegate is invoked. This may be null.
Register​(Action<​object> callback,
object state,
bool useSynchronizationContext)
Registers a delegate that will be called when this <see cref="T:System.Threading.CancellationToken" /> is canceled.
Returns The <see cref="T:System.Threading.CancellationTokenRegistration" /> instance that can be used to unregister the callback.
callback
The delegate to be executed when the <see cref="T:System.Threading.CancellationToken" /> is canceled.
state
The state to pass to the <paramref name="callback" /> when the delegate is invoked. This may be null.
useSynchronizationContext
A Boolean value that indicates whether to capture the current <see cref="T:System.Threading.SynchronizationContext" /> and use it when invoking the <paramref name="callback" /> .
public
void
ThrowIfCancellationRequested​()
Throws a <see cref="T:System.OperationCanceledException" /> if this token has had cancellation requested.
UnsafeRegister​(Action<​object, CancellationToken> callback,
object state)
Registers a delegate that will be called when this <see cref="T:System.Threading.CancellationToken">CancellationToken</see> is canceled.
Returns The <see cref="T:System.Threading.CancellationTokenRegistration" /> instance that can be used to unregister the callback.
callback
The delegate to be executed when the <see cref="T:System.Threading.CancellationToken">CancellationToken</see> is canceled.
state
The state to pass to the <paramref name="callback" /> when the delegate is invoked. This may be <see langword="null" /> .
UnsafeRegister​(Action<​object> callback,
object state)
Registers a delegate that is called when this <see cref="T:System.Threading.CancellationToken" /> is canceled.
Returns An object that can
be used to unregister the callback.
callback
The delegate to execute when the <see cref="T:System.Threading.CancellationToken" /> is canceled.
state
The state to pass to the <paramref name="callback" /> when the delegate is invoked. This may be <see langword="null" /> .
public
string
ToString​()
Inherited from ValueType
Returns the fully qualified type name of this instance.
Returns The fully qualified type name.
protected
void
Finalize​()
Inherited from object
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
public
Type
GetType​()
Inherited from object
Gets the <see cref="T:System.Type" /> of the current instance.
Returns The exact runtime type of the current instance.
protected
object
MemberwiseClone​()
Inherited from object
Creates a shallow copy of the current <see cref="T:System.Object" /> .
Returns A shallow copy of the current <see cref="T:System.Object" /> .