This repository contains the runnable demos that accompany my blog post:
C# Cancellation Tokens In-Depth: Complete Guide with ASP.NET Core Examples
It shows practical, working examples of how to use CancellationToken in C# and ASP.NET Core applications.
Each demo is available as a minimal API endpoint (Program.cs) with a matching front-end page (wwwroot/index.html).
| Endpoint | Description |
|---|---|
/slow |
A slow request that ignores cancellation (what not to do). |
/slow-cancel |
A slow request that honours cancellation using Task.Delay(..., token). |
/ticks |
Manual streaming with cancellation (newline-delimited ticks). |
/parallel |
Running work in parallel with cancellation using Parallel.ForEachAsync. |
/compose |
Composing tasks with cancellation support (multiple awaits). |
/upload |
Throttled file upload to demonstrate mid-transfer cancellation. |