CancellationToken.UnsafeRegister 方法

定义

重载

UnsafeRegister(Action<Object,CancellationToken>, Object)

注册取消此 CancellationToken 时将调用的委托。

UnsafeRegister(Action<Object>, Object)

注册一个在取消此 CancellationToken 时调用的委托。

UnsafeRegister(Action<Object,CancellationToken>, Object)

注册取消此 CancellationToken 时将调用的委托。

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

参数

callback
Action<Object,CancellationToken>

取消 CancellationToken 时要执行的委托。

state
Object

要在调用委托时传递给 callback 的状态。 这可能是 null

返回

CancellationTokenRegistration

可用于注销回调的 CancellationTokenRegistration 实例。

例外

callbacknull

注解

如果此令牌已处于取消状态,则委托将立即和同步运行。 委托生成的任何异常都从此方法调用中传播出来。 ExecutionContext 未捕获或流向回调的调用。

适用于

UnsafeRegister(Action<Object>, Object)

注册一个在取消此 CancellationToken 时调用的委托。

public:
 System::Threading::CancellationTokenRegistration UnsafeRegister(Action<System::Object ^> ^ callback, System::Object ^ state);
public System.Threading.CancellationTokenRegistration UnsafeRegister (Action<object?> callback, object? state);
member this.UnsafeRegister : Action<obj> * obj -> System.Threading.CancellationTokenRegistration
Public Function UnsafeRegister (callback As Action(Of Object), state As Object) As CancellationTokenRegistration

参数

callback
Action<Object>

要在取消 CancellationToken 时执行的委托。

state
Object

要在调用委托时传递给 callback 的状态。 这可能是 null

返回

CancellationTokenRegistration

可用于注销回调的对象。

例外

callback 为 null。

注解

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

ExecutionContext未捕获或流向回调的调用。

适用于