CancellationToken.Register Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Registers a delegate that will be called when this CancellationToken is canceled.
Overloads
Register(Action) |
Registers a delegate that will be called when this CancellationToken is canceled. |
Register(Action, Boolean) |
Registers a delegate that will be called when this CancellationToken is canceled. |
Register(Action<Object,CancellationToken>, Object) |
Registers a delegate that will be called when this CancellationToken is canceled. |
Register(Action<Object>, Object) |
Registers a delegate that will be called when this CancellationToken is canceled. |
Register(Action<Object>, Object, Boolean) |
Registers a delegate that will be called when this CancellationToken is canceled. |
Register(Action)
- Source:
- CancellationToken.cs
- Source:
- CancellationToken.cs
- Source:
- CancellationToken.cs
Registers a delegate that will be called when this CancellationToken is canceled.
public:
System::Threading::CancellationTokenRegistration Register(Action ^ callback);
public System.Threading.CancellationTokenRegistration Register (Action callback);
member this.Register : Action -> System.Threading.CancellationTokenRegistration
Public Function Register (callback As Action) As CancellationTokenRegistration
Parameters
- callback
- Action
The delegate to be executed when the CancellationToken is canceled.
Returns
The CancellationTokenRegistration instance that can be used to unregister the callback.
Exceptions
The associated CancellationTokenSource has been disposed.
callback
is null.
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.
The current SynchronizationContext is not captured.
See also
Applies to
Register(Action, Boolean)
- Source:
- CancellationToken.cs
- Source:
- CancellationToken.cs
- Source:
- CancellationToken.cs
Registers a delegate that will be called when this CancellationToken is canceled.
public:
System::Threading::CancellationTokenRegistration Register(Action ^ callback, bool useSynchronizationContext);
public System.Threading.CancellationTokenRegistration Register (Action callback, bool useSynchronizationContext);
member this.Register : Action * bool -> System.Threading.CancellationTokenRegistration
Public Function Register (callback As Action, useSynchronizationContext As Boolean) As CancellationTokenRegistration
Parameters
- callback
- Action
The delegate to be executed when the CancellationToken is canceled.
- useSynchronizationContext
- Boolean
A 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
The associated CancellationTokenSource has been disposed.
callback
is null.
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
Register(Action<Object,CancellationToken>, Object)
- Source:
- CancellationToken.cs
- Source:
- CancellationToken.cs
- Source:
- CancellationToken.cs
Registers a delegate that will be called when this CancellationToken is canceled.
public:
System::Threading::CancellationTokenRegistration Register(Action<System::Object ^, System::Threading::CancellationToken> ^ callback, System::Object ^ state);
public System.Threading.CancellationTokenRegistration Register (Action<object?,System.Threading.CancellationToken> callback, object? state);
member this.Register : Action<obj, System.Threading.CancellationToken> * obj -> System.Threading.CancellationTokenRegistration
Public Function Register (callback As Action(Of Object, CancellationToken), state As Object) As CancellationTokenRegistration
Parameters
- callback
- Action<Object,CancellationToken>
The delegate to be executed when the CancellationToken is canceled.
- state
- Object
The state to pass to the callback
when the delegate is invoked. This may be null
.
Returns
The CancellationTokenRegistration instance that can be used to unregister the callback.
Exceptions
callback
is null
.
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, if one exists, is captured along with the delegate and is used when executing it. The current SynchronizationContext is not captured.
Applies to
Register(Action<Object>, Object)
- Source:
- CancellationToken.cs
- Source:
- CancellationToken.cs
- Source:
- CancellationToken.cs
Registers a delegate that will be called when this CancellationToken is canceled.
public:
System::Threading::CancellationTokenRegistration Register(Action<System::Object ^> ^ callback, System::Object ^ state);
public System.Threading.CancellationTokenRegistration Register (Action<object> callback, object state);
public System.Threading.CancellationTokenRegistration Register (Action<object?> callback, object? state);
member this.Register : Action<obj> * obj -> System.Threading.CancellationTokenRegistration
Public Function Register (callback As Action(Of Object), state As Object) As CancellationTokenRegistration
Parameters
The delegate to be executed when the CancellationToken is canceled.
- state
- Object
The state to pass to the callback
when the delegate is invoked. This may be null.
Returns
The CancellationTokenRegistration instance that can be used to unregister the callback.
Exceptions
The associated CancellationTokenSource has been disposed.
callback
is null.
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.
The current SynchronizationContext is not captured.
See also
Applies to
Register(Action<Object>, Object, Boolean)
- Source:
- CancellationToken.cs
- Source:
- CancellationToken.cs
- Source:
- CancellationToken.cs
Registers a delegate that will be called when this CancellationToken is canceled.
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
The delegate to be executed when the CancellationToken is canceled.
- 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
The associated CancellationTokenSource has been disposed.
callback
is null.
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
.NET