Aller au contenu

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.

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