Using ConfigureAwait(false) on tasks passed in to Task.WhenAll() fails

后端 未结 1 1630
既然无缘
既然无缘 2020-12-18 18:15

I\'m trying to decide how to wait on all async tasks to complete.

Here is the code I currently have

[HttpGet]
public async Task doA         


        
相关标签:
1条回答
  • 2020-12-18 18:41

    You only need ConfigureAwait when you actually perform the await, the correct form would be

    [HttpGet]
    public async Task<JsonResult> doAsyncStuff()
    {
      var t1 = this.service1.task1();
      var t2 = this.service2.task2();
      var t3 = this.service3.task3();
      var t4 = this.service4.task4();
    
      await Task.WhenAll(t1,t2,t3,t4).ConfigureAwait(false);
      return this.Json(new {redirect = true, href = Url.Action("Blah")}, JsonRequestBehavior.AllowGet);
    }
    
    0 讨论(0)
提交回复
热议问题