ThrowIfCancellation()
where possible CS-R1081The 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
.
if (token.IsCancellationRequested)
{
throw new OperationCanceledException(token);
}
token.ThrowIfCancellationRequested();