CancellationToken.UnsafeRegister(Action<Object>, Object) 方法

定義

註冊取消此 CancellationToken 時要呼叫的委派。Registers a delegate that is called when this CancellationToken is canceled.

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 時要執行的委派。The delegate to execute when the CancellationToken is canceled.

state
Object

當叫用委派時,要傳遞給 callback 的狀態。The state to pass to the callback when the delegate is invoked. 這可能是 nullThis may be null.

傳回

可用來取消註冊回呼的物件。An object that can be used to unregister the callback.

例外狀況

callback 為 null。callback is 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,也不會流向回呼的調用。The ExecutionContext is not captured nor flowed to the callback's invocation.

適用於