How can I allow Task exceptions to propagate back to the UI thread?

后端 未结 4 796
一生所求
一生所求 2021-02-08 11:43

In TPL, if an exception is thrown by a Task, that exception is captured and stored in Task.Exception, and then follows all the rules on observed exceptions. If it\'s never obser

4条回答
  •  温柔的废话
    2021-02-08 12:32

    Does something like this suit?

    public static async void Await(this Task task, Action action = null)
    {
       await task;
       if (action != null)
          action();
    }
    
    runningTask.Await();
    

提交回复
热议问题