OperationCanceledException VS TaskCanceledException when task is canceled

后端 未结 2 496
鱼传尺愫
鱼传尺愫 2021-02-07 04:19

The following code creates a task which is being canceled. await expression (case 1) throws System.OperationCanceledException while synchronous W

2条回答
  •  独厮守ぢ
    2021-02-07 04:37

    TaskCanceledException inherits from OperationCanceledException. So it least there is a little consitency.

    So flatten AggregateException and compare with base should be consistent.

    var ex = exception.Flatten()
    if( ex is OperationCanceledException)
    {
    ...
    }
    

提交回复
热议问题