CancellationTokenSource
CancellationTokenSource is a .NET type that creates and controls cancellation signals represented by CancellationToken values.
C# Concurrency: Asynchronous and multithreaded programming
CancellationTokenSource is a .NET object that creates and controls cancellation tokens, including by requesting cancellation.
- How it is used
- Coordinates cooperative cancellation for background work and asynchronous operations by separating cancellation requests from cancellation checks.
- How deep it goes
- Explains source-token separation, flag-based observation, delayed cancellation, timeouts, callbacks, and linked sources without detailing token internals.
- Examples
- Demonstrates cancellable background threads, long calculations, and HTTP requests canceled by either a user token or a timeout.
- What you can do after
- Operate/configure cooperative cancellation by creating sources, calling Cancel or CancelAfter, linking tokens, and passing tokens to cancelable operations.
.NET in Action, Second Edition
CancellationTokenSource is a .NET type that creates and controls cancellation signals represented by CancellationToken values.
- How it is used
- Coordinates stopping asynchronous file or network work when its result is no longer needed.
- How deep it goes
- Shows source creation, token checks, and forwarding through async calls; does not show the source being triggered.
- Examples
- Uses an asynchronous comic search that passes one source’s token to fetching tasks.
- What you can do after
- Apply it via .NET async APIs to pass a shared cancellation token into HTTP requests and deserialization.
Read how .NET in Action, Second Edition explains CancellationTokenSource →
Related concepts
- CancellationTokenproduces · CancellationToken is a .NET value that communicates a cooperative request to cancel an asynchronous or otherwise cancellable operation.
- timeoutconfigured by · A timeout is a configured time limit after which an incomplete operation or wait is stopped, abandoned, or treated as unsuccessful.
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.

