Multiple async/await chaining

前端 未结 3 2072
离开以前
离开以前 2021-01-06 22:50

How to make multiple async/await chaining in C#? For example, start few HTTP requests and then do not wait all of them, but start new request after each completed?<

3条回答
  •  隐瞒了意图╮
    2021-01-06 23:34

    The easiest way to do this is to write an async method:

    async Task DownloadAndFollowupAsync(...)
    {
      await DownloadAsync();
      await FollowupAsync();
    }
    

    Which you can then use with await Task.WhenAll:

    await Task.WhenAll(DownloadAndFollowupAsync(...),
        DownloadAndFollowupAsync(...));
    

提交回复
热议问题