CancellationToken.Register Method (System.Threading)

Source:
CancellationToken.cs
Source:
CancellationToken.cs
Source:
CancellationToken.cs
Source:
CancellationToken.cs
Source:
CancellationToken.cs
public:
 System::Threading::CancellationTokenRegistration Register(Action<System::Object ^> ^ callback, System::Object ^ state, bool useSynchronizationContext);
public System.Threading.CancellationTokenRegistration Register(Action<object> callback, object state, bool useSynchronizationContext);
public System.Threading.CancellationTokenRegistration Register(Action<object?> callback, object? state, bool useSynchronizationContext);
member this.Register : Action<obj> * obj * bool -> System.Threading.CancellationTokenRegistration
Public Function Register (callback As Action(Of Object), state As Object, useSynchronizationContext As Boolean) As CancellationTokenRegistration

Parameters

state
Object

The state to pass to the callback when the delegate is invoked. This may be null.

useSynchronizationContext
Boolean

A Boolean value that indicates whether to capture the current SynchronizationContext and use it when invoking the callback.

Returns

The CancellationTokenRegistration instance that can be used to unregister the callback.

Exceptions

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 propagated out of this method call.

The current ExecutionContext is captured along with the delegate and will be used when executing it.

If useSynchronizationContext is true, the current SynchronizationContext, if one exists, is also captured along with the delegate and will be used when executing it. Otherwise, SynchronizationContext is not captured.

See also

Applies to