Skip to main content
InterviewHubPRO
Section Overview
Q7

Question 7 of 50

Part 1: Request Pipeline, Dependency Injection & Web APIs (1 - 10)

14%
ASP.NET Core & Web API (50 Qs)•Part 1: Request Pipeline, Dependency Injection & Web APIs (1 - 10)

What is `CancellationToken` and why must you pass it to all async database and HTTP calls?

junior LevelMost AskedDependency InjectionPipesAsync & Promises

In Simple Words: A CancellationToken notifies async operations that the client disconnected or the request timed out:

  • If a user cancels an HTTP request or navigates away, passing CancellationToken to EF Core (SaveChangesAsync(ct)) or HttpClient immediately cancels the database query on the SQL server and releases the thread, preventing wasted database CPU cycles.