Why doesn't await on Task.WhenAll throw an AggregateException?

前端 未结 8 1763
我在风中等你
我在风中等你 2020-12-04 15:14

In this code:

private async void button1_Click(object sender, EventArgs e) {
    try {
        await Task.WhenAll(DoLongThingAsyncEx1(), DoLongThingAsyncEx2(         


        
8条回答
  •  鱼传尺愫
    2020-12-04 15:41

    You're thinking of Task.WaitAll - it throws an AggregateException.

    WhenAll just throws the first exception of the list of exceptions it encounters.

提交回复
热议问题