CancellationTokenRegistration 结构

定义

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

public value class CancellationTokenRegistration : IDisposable, IEquatable<System::Threading::CancellationTokenRegistration>
public struct CancellationTokenRegistration : IDisposable, IEquatable<System.Threading.CancellationTokenRegistration>
type CancellationTokenRegistration = struct
    interface IDisposable
Public Structure CancellationTokenRegistration
Implements 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. 如果注册未与令牌关联(例如在释放注册后),这将返回默认令牌。If the registration isn't associated with a token (such as after the registration has been disposed), this will return a default token.

方法

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.

适用于

线程安全性

CancellationTokenRegistration 的所有公共和受保护成员都是线程安全的,并且可以从多个线程并发使用,而 Dispose 除外,只需在 CancellationTokenRegistration 上的所有其他操作都完成时使用。All 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.

另请参阅