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

前端 未结 5 1788
旧巷少年郎
旧巷少年郎 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:28

    If you don't get any callbacks or the control hangs up, after calling the service/API async function, you have to configure Context to return a result on the same called context.

    Use TestAsync().ConfigureAwait(continueOnCapturedContext: false);

    You will be facing this issue only in web applications, but not in static void main.

提交回复
热议问题