System.Threading.CancellationToken.Register Method

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

Syntax

public CancellationTokenRegistration Register (Action callback, bool useSynchronizationContext)

Parameters

callback
The delegate to be executed when the System.Threading.CancellationToken is canceled.
useSynchronizationContext
A Boolean value that indicates whether to capture the current System.Threading.SynchronizationContext and use it when invoking the callback.

Returns

The System.Threading.CancellationTokenRegistration instance that can be used to deregister the callback.

Remarks

If this token is already in the canceled state, the delegate will be run immediately and synchronously. Any exception the delegate generates will be propogated out of this method call.

The current System.Threading.ExecutionContext, if one exists, will be captured along with the delegate and will be used when executing it.

Requirements

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