CancellationToken
CancellationToken is a .NET value that communicates a cooperative request to cancel an asynchronous or otherwise cancellable operation.
C# Concurrency: Asynchronous and multithreaded programming
A CancellationToken is a .NET value that communicates a request to cancel an asynchronous or otherwise cancellable operation.
- How it is used
- Coordinates cooperative cancellation for background threads, asynchronous operations, and asynchronous iteration.
- How deep it goes
- Explains source-token separation, polling, delayed cancellation, callbacks, timeouts, linked sources, and async-iterator propagation.
- Examples
- Demonstrates cancelable background loops, long calculations, Task.Delay, async iterators, and await foreach with WithCancellation.
- What you can do after
- Apply it via .NET APIs to design cooperative cancellation and propagate requests through long-running and asynchronous workflows.
Read how C# Concurrency: Asynchronous and multithreaded programming explains CancellationToken →
.NET in Action, Second Edition
A cancellation token is a .NET value that communicates a cooperative request for an operation to stop.
- How it is used
- Coordinates stopping unwanted asynchronous I/O work, including requests made during a title search.
- How deep it goes
- Shows an explicit parameter, a pre-request check, and token propagation into HTTP and JSON APIs.
- Examples
- Uses an asynchronous comic lookup and a search that shares a token across lookup tasks.
- What you can do after
- Apply it by accepting a token, checking for cancellation, and passing it to asynchronous operations.
Read how .NET in Action, Second Edition explains CancellationToken →
Related concepts
- CancellationTokenSourceproduced by · CancellationTokenSource is a .NET type that creates and controls cancellation signals represented by CancellationToken values.
- taskused by · A task is a defined unit of work, computation, or action directed toward a result or objective.
- WithCancellationused by · WithCancellation is a .NET extension method that associates a cancellation token with an IAsyncEnumerable<T> for asynchronous iteration.
- .NETused by · .NET is Microsoft's cross-platform development platform, providing runtimes, libraries, and tools for building and running applications.
- background serviceused by · A background service is a long-running process or application component that performs work without requiring direct interactive input.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

