C#

C#

Made by DeepSource

Consider using ThrowIfCancellation() where possible CS-R1081

Anti-pattern
Major
Autofix

The CancellationToken.IsCancellationRequested property specifies if cancellation is requested for a token. In a subset of such cases, OperationCanceledException exception is thrown. However, this entire snippet can be replaced with CancellationToken.ThrowIfCancellation.

Bad Practice

if (token.IsCancellationRequested)
{
    throw new OperationCanceledException(token);
}

Recommended

token.ThrowIfCancellationRequested();

Reference