HttpClient.GetAsync(…) never returns when using await/async

前端 未结 6 772
[愿得一人]
[愿得一人] 2020-11-22 12:22

Edit: This question looks like it might be the same problem, but has no responses...

Edit: In test case 5 the task appears to be st

6条回答
  •  有刺的猬
    2020-11-22 13:05

    Since you are using .Result or .Wait or await this will end up causing a deadlock in your code.

    you can use ConfigureAwait(false) in async methods for preventing deadlock

    like this:

    var result = await httpClient.GetAsync("http://stackoverflow.com", HttpCompletionOption.ResponseHeadersRead)
                                 .ConfigureAwait(false);
    

    you can use ConfigureAwait(false) wherever possible for Don't Block Async Code .

提交回复
热议问题