When a C# async method returns a value, cancellation via CancellationToken creates a dilemma: you must either return a dummy value or throw an exception. Returning a sentinel value like -1 is misleading to readers. The cleaner alternative is calling token.ThrowIfCancellationRequested(), which throws an OperationCanceledException that callers can catch. A code example shows running two tasks with Task.WhenAny, canceling the remaining task after the first completes, and handling the resulting exception in a foreach loop.
3 Impressions