mscorlib(4.0.0.0) API with additions
System.Threading.CancellationToken Struct Reference

Propagates notification that operations should be canceled. More...

Public Member Functions

internal CancellationToken (CancellationTokenSource source)
 
 CancellationToken (bool canceled)
 Initializes the T:System.Threading.CancellationToken. More...
 
CancellationTokenRegistration Register (Action callback)
 Registers a delegate that will be called when this T:System.Threading.CancellationToken is canceled. More...
 
CancellationTokenRegistration Register (Action callback, bool useSynchronizationContext)
 Registers a delegate that will be called when this T:System.Threading.CancellationToken is canceled. More...
 
CancellationTokenRegistration Register (Action< object > callback, object state)
 Registers a delegate that will be called when this T:System.Threading.CancellationToken is canceled. More...
 
CancellationTokenRegistration Register (Action< object > callback, object state, bool useSynchronizationContext)
 Registers a delegate that will be called when this T:System.Threading.CancellationToken is canceled. More...
 
internal CancellationTokenRegistration InternalRegisterWithoutEC (Action< object > callback, object state)
 
bool Equals (CancellationToken other)
 Determines whether the current T:System.Threading.CancellationToken instance is equal to the specified token. More...
 
override bool Equals (object other)
 Determines whether the current T:System.Threading.CancellationToken instance is equal to the specified T:System.Object. More...
 
override int GetHashCode ()
 Serves as a hash function for a T:System.Threading.CancellationToken. More...
 
void ThrowIfCancellationRequested ()
 Throws a T:System.OperationCanceledException if this token has had cancellation requested. More...
 
internal void ThrowIfSourceDisposed ()
 

Static Public Member Functions

static bool operator== (CancellationToken left, CancellationToken right)
 Determines whether two T:System.Threading.CancellationToken instances are equal. More...
 
static bool operator != (CancellationToken left, CancellationToken right)
 Determines whether two T:System.Threading.CancellationToken instances are not equal. More...
 

Properties

static CancellationToken None [get]
 Returns an empty T:System.Threading.CancellationToken value. More...
 
bool IsCancellationRequested [get]
 Gets whether cancellation has been requested for this token. More...
 
bool CanBeCanceled [get]
 Gets whether this token is capable of being in the canceled state. More...
 
WaitHandle WaitHandle [get]
 Gets a T:System.Threading.WaitHandle that is signaled when the token is canceled. More...
 

Detailed Description

Propagates notification that operations should be canceled.

Definition at line 14 of file CancellationToken.cs.

Constructor & Destructor Documentation

◆ CancellationToken()

System.Threading.CancellationToken.CancellationToken ( bool  canceled)

Initializes the T:System.Threading.CancellationToken.

Parameters
canceledThe canceled state for the token.

Definition at line 91 of file CancellationToken.cs.

Member Function Documentation

◆ Equals() [1/2]

bool System.Threading.CancellationToken.Equals ( CancellationToken  other)

Determines whether the current T:System.Threading.CancellationToken instance is equal to the specified token.

Parameters
otherThe other T:System.Threading.CancellationToken to which to compare this instance.
Returns
true if the instances are equal; otherwise, false. Two tokens are equal if they are associated with the same T:System.Threading.CancellationTokenSource or if they were both constructed from public T:System.Threading.CancellationToken constructors and their P:System.Threading.CancellationToken.IsCancellationRequested values are equal.

Definition at line 209 of file CancellationToken.cs.

◆ Equals() [2/2]

override bool System.Threading.CancellationToken.Equals ( object  other)

Determines whether the current T:System.Threading.CancellationToken instance is equal to the specified T:System.Object.

Parameters
otherThe other object to which to compare this instance.
Returns
true if other is a T:System.Threading.CancellationToken and if the two instances are equal; otherwise, false. Two tokens are equal if they are associated with the same T:System.Threading.CancellationTokenSource or if they were both constructed from public T:System.Threading.CancellationToken constructors and their P:System.Threading.CancellationToken.IsCancellationRequested values are equal.
Exceptions
T:System.ObjectDisposedExceptionAn associated T:System.Threading.CancellationTokenSource has been disposed.

Definition at line 232 of file CancellationToken.cs.

◆ GetHashCode()

override int System.Threading.CancellationToken.GetHashCode ( )

Serves as a hash function for a T:System.Threading.CancellationToken.

Returns
A hash code for the current T:System.Threading.CancellationToken instance.

Definition at line 244 of file CancellationToken.cs.

◆ operator !=()

static bool System.Threading.CancellationToken.operator != ( CancellationToken  left,
CancellationToken  right 
)
static

Determines whether two T:System.Threading.CancellationToken instances are not equal.

Parameters
leftThe first instance.
rightThe second instance.
Returns
true if the instances are not equal; otherwise, false.
Exceptions
T:System.ObjectDisposedExceptionAn associated T:System.Threading.CancellationTokenSource has been disposed.

Definition at line 272 of file CancellationToken.cs.

◆ operator==()

static bool System.Threading.CancellationToken.operator== ( CancellationToken  left,
CancellationToken  right 
)
static

Determines whether two T:System.Threading.CancellationToken instances are equal.

Parameters
leftThe first instance.
rightThe second instance.
Returns
true if the instances are equal; otherwise, false.
Exceptions
T:System.ObjectDisposedExceptionAn associated T:System.Threading.CancellationTokenSource has been disposed.

Definition at line 260 of file CancellationToken.cs.

◆ Register() [1/4]

CancellationTokenRegistration System.Threading.CancellationToken.Register ( Action  callback)

Registers a delegate that will be called when this T:System.Threading.CancellationToken is canceled.

Parameters
callbackThe delegate to be executed when the T:System.Threading.CancellationToken is canceled.
Returns
The T:System.Threading.CancellationTokenRegistration instance that can be used to deregister the callback.
Exceptions
T:System.ObjectDisposedExceptionThe associated T:System.Threading.CancellationTokenSource has been disposed.
T:System.ArgumentNullExceptioncallback is null.

Definition at line 113 of file CancellationToken.cs.

◆ Register() [2/4]

CancellationTokenRegistration System.Threading.CancellationToken.Register ( Action  callback,
bool  useSynchronizationContext 
)

Registers a delegate that will be called when this T:System.Threading.CancellationToken is canceled.

Parameters
callbackThe delegate to be executed when the T:System.Threading.CancellationToken is canceled.
useSynchronizationContextA value that indicates whether to capture the current T:System.Threading.SynchronizationContext and use it when invoking the callback .
Returns
The T:System.Threading.CancellationTokenRegistration instance that can be used to deregister the callback.
Exceptions
T:System.ObjectDisposedExceptionThe associated T:System.Threading.CancellationTokenSource has been disposed.
T:System.ArgumentNullExceptioncallback is null.

Definition at line 130 of file CancellationToken.cs.

◆ Register() [3/4]

CancellationTokenRegistration System.Threading.CancellationToken.Register ( Action< object >  callback,
object  state 
)

Registers a delegate that will be called when this T:System.Threading.CancellationToken is canceled.

Parameters
callbackThe delegate to be executed when the T:System.Threading.CancellationToken is canceled.
stateThe state to pass to the callback when the delegate is invoked. This may be null.
Returns
The T:System.Threading.CancellationTokenRegistration instance that can be used to deregister the callback.
Exceptions
T:System.ObjectDisposedExceptionThe associated T:System.Threading.CancellationTokenSource has been disposed.
T:System.ArgumentNullExceptioncallback is null.

Definition at line 147 of file CancellationToken.cs.

◆ Register() [4/4]

CancellationTokenRegistration System.Threading.CancellationToken.Register ( Action< object >  callback,
object  state,
bool  useSynchronizationContext 
)

Registers a delegate that will be called when this T:System.Threading.CancellationToken is canceled.

Parameters
callbackThe delegate to be executed when the T:System.Threading.CancellationToken is canceled.
stateThe state to pass to the callback when the delegate is invoked. This may be null.
useSynchronizationContextA Boolean value that indicates whether to capture the current T:System.Threading.SynchronizationContext and use it when invoking the callback .
Returns
The T:System.Threading.CancellationTokenRegistration instance that can be used to deregister the callback.
Exceptions
T:System.ObjectDisposedExceptionThe associated T:System.Threading.CancellationTokenSource has been disposed.
T:System.ArgumentNullExceptioncallback is null.

Definition at line 165 of file CancellationToken.cs.

◆ ThrowIfCancellationRequested()

void System.Threading.CancellationToken.ThrowIfCancellationRequested ( )

Throws a T:System.OperationCanceledException if this token has had cancellation requested.

Exceptions
T:System.OperationCanceledExceptionThe token has had cancellation requested.
T:System.ObjectDisposedExceptionThe associated T:System.Threading.CancellationTokenSource has been disposed.

Definition at line 281 of file CancellationToken.cs.

Property Documentation

◆ CanBeCanceled

bool System.Threading.CancellationToken.CanBeCanceled
get

Gets whether this token is capable of being in the canceled state.

Returns
true if this token is capable of being in the canceled state; otherwise, false.

Definition at line 54 of file CancellationToken.cs.

◆ IsCancellationRequested

bool System.Threading.CancellationToken.IsCancellationRequested
get

Gets whether cancellation has been requested for this token.

Returns
true if cancellation has been requested for this token; otherwise, false.

Definition at line 37 of file CancellationToken.cs.

◆ None

CancellationToken System.Threading.CancellationToken.None
staticget

Returns an empty T:System.Threading.CancellationToken value.

Returns
An empty cancellation token.

Definition at line 24 of file CancellationToken.cs.

◆ WaitHandle

WaitHandle System.Threading.CancellationToken.WaitHandle
get

Gets a T:System.Threading.WaitHandle that is signaled when the token is canceled.

Returns
A T:System.Threading.WaitHandle that is signaled when the token is canceled.
Exceptions
T:System.ObjectDisposedExceptionThe associated T:System.Threading.CancellationTokenSource has been disposed.

Definition at line 71 of file CancellationToken.cs.


The documentation for this struct was generated from the following file: