CancellationToken.Register CancellationToken.Register CancellationToken.Register CancellationToken.Register Method

定义

注册一个将在取消此 CancellationToken 时调用的委托。Registers a delegate that will be called when this CancellationToken is canceled.

重载

Register(Action) Register(Action) Register(Action) Register(Action)

注册一个将在取消此 CancellationToken 时调用的委托。Registers a delegate that will be called when this CancellationToken is canceled.

Register(Action, Boolean) Register(Action, Boolean) Register(Action, Boolean) Register(Action, Boolean)

注册一个将在取消此 CancellationToken 时调用的委托。Registers a delegate that will be called when this CancellationToken is canceled.

Register(Action<Object>, Object) Register(Action<Object>, Object) Register(Action<Object>, Object) Register(Action<Object>, Object)

注册一个将在取消此 CancellationToken 时调用的委托。Registers a delegate that will be called when this CancellationToken is canceled.

Register(Action<Object>, Object, Boolean) Register(Action<Object>, Object, Boolean) Register(Action<Object>, Object, Boolean) Register(Action<Object>, Object, Boolean)

注册一个将在取消此 CancellationToken 时调用的委托。Registers a delegate that will be called when this CancellationToken is canceled.

Register(Action) Register(Action) Register(Action) Register(Action)

注册一个将在取消此 CancellationToken 时调用的委托。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

参数

callback
Action Action Action Action

要在取消 CancellationToken 时执行的委托。The delegate to be executed when the CancellationToken is canceled.

返回

异常

注解

如果此令牌已处于已取消状态,立即并以同步方式将运行该委托。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.

当前ExecutionContext与委托一起捕获并将执行它时使用。The current ExecutionContext is captured along with the delegate and will be used when executing it.

当前SynchronizationContext不捕获。The current SynchronizationContext is not captured.

另请参阅

Register(Action, Boolean) Register(Action, Boolean) Register(Action, Boolean) Register(Action, Boolean)

注册一个将在取消此 CancellationToken 时调用的委托。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

参数

callback
Action Action Action Action

要在取消 CancellationToken 时执行的委托。The delegate to be executed when the CancellationToken is canceled.

useSynchronizationContext
Boolean Boolean Boolean Boolean

一个值,该值指示是否捕获当前 SynchronizationContext 并在调用 callback 时使用。A value that indicates whether to capture the current SynchronizationContext and use it when invoking the callback.

返回

异常

注解

如果此令牌已处于已取消状态,立即并以同步方式将运行该委托。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.

当前ExecutionContext与委托一起捕获并将执行它时使用。The current ExecutionContext is captured along with the delegate and will be used when executing it.

如果useSynchronizationContexttrue,当前SynchronizationContext,一个存在、 是否与委托一起还捕获,将执行它时使用。If useSynchronizationContext is true, the current SynchronizationContext, if one exists, is also captured along with the delegate and will be used when executing it. 否则为SynchronizationContext不捕获。Otherwise, SynchronizationContext is not captured.

另请参阅

Register(Action<Object>, Object) Register(Action<Object>, Object) Register(Action<Object>, Object) Register(Action<Object>, Object)

注册一个将在取消此 CancellationToken 时调用的委托。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);
member this.Register : Action<obj> * obj -> System.Threading.CancellationTokenRegistration
Public Function Register (callback As Action(Of Object), state As Object) As CancellationTokenRegistration

参数

callback
Action<Object>

要在取消 CancellationToken 时执行的委托。The delegate to be executed when the CancellationToken is canceled.

state
Object Object Object Object

要在调用委托时传递给 callback 的状态。The state to pass to the callback when the delegate is invoked. 这可能为 null。This may be null.

返回

异常

注解

如果此令牌已处于已取消状态,立即并以同步方式将运行该委托。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.

当前ExecutionContext与委托一起捕获并将执行它时使用。The current ExecutionContext is captured along with the delegate and will be used when executing it.

当前SynchronizationContext不捕获。The current SynchronizationContext is not captured.

另请参阅

Register(Action<Object>, Object, Boolean) Register(Action<Object>, Object, Boolean) Register(Action<Object>, Object, Boolean) Register(Action<Object>, Object, Boolean)

注册一个将在取消此 CancellationToken 时调用的委托。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);
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

参数

callback
Action<Object>

要在取消 CancellationToken 时执行的委托。The delegate to be executed when the CancellationToken is canceled.

state
Object Object Object Object

要在调用委托时传递给 callback 的状态。The state to pass to the callback when the delegate is invoked. 这可能为 null。This may be null.

useSynchronizationContext
Boolean Boolean Boolean Boolean

一个布尔值,该值指示是否捕获当前 SynchronizationContext 并在调用 callback 时使用它。A Boolean value that indicates whether to capture the current SynchronizationContext and use it when invoking the callback.

返回

异常

注解

如果此令牌已处于已取消状态,立即并以同步方式将运行该委托。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.

当前ExecutionContext与委托一起捕获并将执行它时使用。The current ExecutionContext is captured along with the delegate and will be used when executing it.

如果useSynchronizationContexttrue,当前SynchronizationContext,一个存在、 是否与委托一起还捕获,将执行它时使用。If useSynchronizationContext is true, the current SynchronizationContext, if one exists, is also captured along with the delegate and will be used when executing it. 否则为SynchronizationContext不捕获。Otherwise, SynchronizationContext is not captured.

另请参阅

适用于