The following code creates a task which is being canceled. await expression (case 1) throws System.OperationCanceledException while synchronous W
await
System.OperationCanceledException
W
TaskCanceledException inherits from OperationCanceledException. So it least there is a little consitency.
TaskCanceledException
OperationCanceledException
So flatten AggregateException and compare with base should be consistent.
var ex = exception.Flatten() if( ex is OperationCanceledException) { ... }