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

前端 未结 5 1781
旧巷少年郎
旧巷少年郎 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条回答
  •  抹茶落季
    2020-11-22 00:35

    You're running into the standard deadlock situation that I describe on my blog and in an MSDN article: the async method is attempting to schedule its continuation onto a thread that is being blocked by the call to Result.

    In this case, your SynchronizationContext is the one used by NUnit to execute async void test methods. I would try using async Task test methods instead.

提交回复
热议问题