Skip to content

Use ThrowIfCancellationRequested (CA2250)

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();