CancellationTokenDisposable sealed class CancellationTokenDisposable : IDisposable Documentation Code using System.Runtime.CompilerServices; using System.Threading; namespace System.Linq { internal sealed class CancellationTokenDisposable : IDisposable { [System.Runtime.CompilerServices.Nullable(1)] private readonly CancellationTokenSource _cts = new CancellationTokenSource(); public CancellationToken Token => _cts.Token; public void Dispose() { if (!_cts.IsCancellationRequested) _cts.Cancel(); } } }