Use ThrowIfCancellationRequested (CA2250)
Ce contenu n’est pas encore disponible dans votre langue.
Key dotnet.async.use-throwifcancellationrequested · Severity info · Category async
Microsoft analyzer CA2250. Flags a hand-written IsCancellationRequested check that throws OperationCanceledException - ThrowIfCancellationRequested says the same and carries the token.
Incorrect
Section titled “Incorrect”if (cancellationToken.IsCancellationRequested) throw new OperationCanceledException();Correct
Section titled “Correct”cancellationToken.ThrowIfCancellationRequested();