'await' works, but calling task.Result hangs/deadlocks

前端 未结 5 1867
旧巷少年郎
旧巷少年郎 2020-11-21 23:56

I have the following four tests and the last one hangs when I run it. Why does this happen:

[Test]
public void CheckOnceResultTest()
{
    Assert.IsTrue(Check         


        
5条回答
  •  猫巷女王i
    2020-11-22 00:15

    You can avoid deadlock adding ConfigureAwait(false) to this line:

    IRestResponse response = await restResponse;
    

    =>

    IRestResponse response = await restResponse.ConfigureAwait(false);
    

    I've described this pitfall in my blog post Pitfalls of async/await

提交回复
热议问题