liveBook · Manning

CancellationToken

CancellationToken is a .NET value that communicates a cooperative request to cancel an asynchronous or otherwise cancellable operation.

How 2 Manning books explain it

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

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.