tubeshowcase●1,665,703 videos♡ My collection 0
← Learn to Code

Learn to Code55:22

Cancellation Tokens with Stephen Toub

dotnet ↗

From the creator

Scott and Stephen are back with another episode of Deep .NET, this time tackling Cancellation Tokens. From the early days of .NET’s “violent” thread aborts to today’s cooperative cancellation model, they explore how tokens provide a safe, composable way to stop work you no longer need. Stephen walks through the evolution from APM and EPM patterns, explains why explicit token passing beats ambient scopes, and shows how cancellation propagates through async calls. Along the way, they dig into cancellation token sources, registration callbacks, and even the role of volatile in multi-threaded code. If you’ve ever wondered how to gracefully cancel tasks without wasting resources, this episode is for you. ⌚ Chapters: 00:00:00 Introduction, banter, and setup for Deep .NET episode 00:03:15 Why cancellation matters: performance and avoiding wasted work 00:07:42 Early .NET approaches: thread aborts and their problems 00:12:10 Evolution of async patterns: APM and EPM without cancellation 00:17:25 BackgroundWorker and early cancellation mechanisms 00:21:40 Composition challenges and the need for a shared token model 00:25:30 Introduction of CancellationToken and cooperative cancellation 00:30:55 Passing tokens explicitly vs. ambient scopes 00:36:20 How cancellation propagates through async methods 00:41:05 Leaf operations, registration callbacks, and prompt cancellation 00:46:50 CancellationTokenSource: producing and linking tokens 00:52:15 Separation of observing vs. requesting cancell

Published 2025-12-05 · Watch on YouTube ↗
Availability and playback restrictions are controlled by the original channel.

Keep exploring Learn to Code