Zum Inhalt springen

Use ThrowIfCancellationRequested (CA2250)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

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.

if (cancellationToken.IsCancellationRequested)
throw new OperationCanceledException();
cancellationToken.ThrowIfCancellationRequested();