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 →
Also covered in
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 discrete unit of work, activity, or computation to be performed or completed.
- WithCancellationused by · WithCancellation is a .NET extension method that associates a cancellation token with an IAsyncEnumerable<T> for asynchronous iteration.
- background serviceused by · A background service is a long-running process or application component that performs work without requiring direct interactive input.
- HttpContextequivalent to · HttpContext is the ASP.NET Core object representing the information, state, and features associated with a single HTTP request and its response.
Questions about CancellationToken
What is CancellationToken?
CancellationToken is a .NET value that communicates a cooperative request to cancel an asynchronous or otherwise cancellable operation.
Which Manning books explain CancellationToken?
C# Concurrency: Asynchronous and multithreaded programming and .NET in Action, Second Edition.
What kinds of CancellationToken are there?
Kinds of CancellationToken include CancellationToken.None.
What is CancellationToken also called?
CancellationToken is also called cancellation token.
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.

