Skip to content
Preptima
mediumConceptCodingScenarioMidSenior

A client disconnects but your server keeps working on their request. How does cancellation actually propagate in .NET?

A CancellationToken in C# is cooperative cancellation, not a thread abort. Pass it through async calls, check it around long CPU loops, and define whether cancelled work leaves durable side effects behind.

4 min readUpdated 2026-08-15

Answer

Short answer

Accept a CancellationToken, pass it to cancellable APIs, and periodically observe it in long-running work. Cancellation only works where code cooperates, so design the operation's side effects and cleanup explicitly.

Was this answer helpful?

Likely follow-ups

  • Where does the token in an ASP.NET Core action come from?
  • Should a cancelled request be logged as an error? What status should it return?
  • You are halfway through writing to the database when cancellation fires. What now?
  • How do you add a timeout to an operation that already has a caller's token?

Related questions

Further reading