CancellationTokenRegistration 结构

定义

表示已向 CancellationToken 注册的回调委托。Represents a callback delegate that has been registered with a CancellationToken.

public value class CancellationTokenRegistration : IDisposable, IEquatable<System::Threading::CancellationTokenRegistration>
public value class CancellationTokenRegistration : IAsyncDisposable, IDisposable, IEquatable<System::Threading::CancellationTokenRegistration>
public struct CancellationTokenRegistration : IDisposable, IEquatable<System.Threading.CancellationTokenRegistration>
public struct CancellationTokenRegistration : IAsyncDisposable, IDisposable, IEquatable<System.Threading.CancellationTokenRegistration>
type CancellationTokenRegistration = struct
    interface IDisposable
type CancellationTokenRegistration = struct
    interface IAsyncDisposable
    interface IDisposable
Public Structure CancellationTokenRegistration
Implements IDisposable, IEquatable(Of CancellationTokenRegistration)
Public Structure CancellationTokenRegistration
Implements IAsyncDisposable, IDisposable, IEquatable(Of CancellationTokenRegistration)
继承
CancellationTokenRegistration
实现

注解

取消标记时调用回调。The callback is called when the token is canceled. 若要注销回调,请释放相应的注册实例。To unregister a callback, dispose the corresponding Registration instance. 有关详细信息和代码示例,请参阅 托管线程中的取消For more information and code examples see Cancellation in Managed Threads.

属性

Token

获取与此注册关联的 CancellationTokenGets the CancellationToken with which this registration is associated.

方法

Dispose()

释放 CancellationTokenRegistration 类的当前实例所使用的所有资源。Releases all resources used by the current instance of the CancellationTokenRegistration class.

DisposeAsync()

释放注册并从关联的 CancellationToken 注销目标回调。Disposes of the registration and unregisters the target callback from the associated CancellationToken.

Equals(CancellationTokenRegistration)

确定当前的 CancellationTokenRegistration 实例是否等于指定的 CancellationTokenRegistrationDetermines whether the current CancellationTokenRegistration instance is equal to the specified CancellationTokenRegistration.

Equals(Object)

确定当前的 CancellationTokenRegistration 实例是否等于指定的 CancellationTokenRegistrationDetermines whether the current CancellationTokenRegistration instance is equal to the specified CancellationTokenRegistration.

GetHashCode()

作为 CancellationTokenRegistration 的哈希函数。Serves as a hash function for a CancellationTokenRegistration.

Unregister()

释放注册并从关联的 CancellationToken 注销目标回调。Disposes of the registration and unregisters the target callback from the associated CancellationToken.

运算符

Equality(CancellationTokenRegistration, CancellationTokenRegistration)

确定两个 CancellationTokenRegistration 实例是否相等。Determines whether two CancellationTokenRegistration instances are equal.

Inequality(CancellationTokenRegistration, CancellationTokenRegistration)

确定两个 CancellationTokenRegistration 实例是否不相等。Determines whether two CancellationTokenRegistration instances are not equal.

扩展方法

ConfigureAwait(IAsyncDisposable, Boolean)

配置如何执行从异步可处置项返回的任务的等待。Configures how awaits on the tasks returned from an async disposable are performed.

适用于

线程安全性

的所有公共和受保护的成员 CancellationTokenRegistration 都是线程安全的,并且可以从多个线程并发使用,而 Dispose 除外,只需在上的所有其他操作完成后使用 CancellationTokenRegistrationAll public and protected members of CancellationTokenRegistration are thread-safe and may be used concurrently from multiple threads, with the exception of Dispose, which must only be used when all other operations on the CancellationTokenRegistration have completed.

另请参阅