CancellationTokenRegistration Struct

Definition

Represents a callback delegate that has been registered with a CancellationToken.

C#
public struct CancellationTokenRegistration : IDisposable, IEquatable<System.Threading.CancellationTokenRegistration>
C#
public readonly struct CancellationTokenRegistration : IAsyncDisposable, IDisposable, IEquatable<System.Threading.CancellationTokenRegistration>
C#
public readonly struct CancellationTokenRegistration : IDisposable, IEquatable<System.Threading.CancellationTokenRegistration>
Inheritance
CancellationTokenRegistration
Implements

Remarks

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.

Properties

Token

Gets the CancellationToken with which this registration is associated.

Methods

Dispose()

Disposes of the registration and unregisters the target callback from the associated CancellationToken.

DisposeAsync()

Disposes of the registration and unregisters the target callback from the associated CancellationToken.

Equals(CancellationTokenRegistration)

Determines whether the current CancellationTokenRegistration instance is equal to the specified CancellationTokenRegistration.

Equals(Object)

Determines whether the current CancellationTokenRegistration instance is equal to the specified CancellationTokenRegistration.

GetHashCode()

Serves as a hash function for a CancellationTokenRegistration.

Unregister()

Disposes of the registration and unregisters the target callback from the associated CancellationToken.

Operators

Extension Methods

ConfigureAwait(IAsyncDisposable, Boolean)

Configures how awaits on the tasks returned from an async disposable will be performed.

Applies to

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Thread Safety

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.

See also