dotnet/runtime

[Analyzer] Async methods that don't take a CancellationToken

Open

#78,397 opened on Nov 15, 2022

View on GitHub
 (7 comments) (11 reactions) (1 assignee)C# (5,445 forks)batch import
api-approvedarea-System.Threading.Taskscode-analyzerhelp wanted

Repository metrics

Stars
 (17,886 stars)
PR merge metrics
 (Avg merge 12d 11h) (661 merged PRs in 30d)

Description

Cancellation is often important to the scalability of an app / service. If an async method has no way to cancel it, that can impact scalability and responsiveness. We should consider adding an analyzer (likely off by default due to noise) that flags async methods (async and/or Task/ValueTask-returning) that have no overloads which accept a CancellationToken, and issue a diagnostic to consider taking one.

Contributor guide