Mixing async/await with Result

前端 未结 2 471
一个人的身影
一个人的身影 2021-02-14 22:43

Let me just preface this question with a few things:

  1. I\'ve read several SO questions saying that you should not do this (such as How to safely mix
2条回答
  •  盖世英雄少女心
    2021-02-14 23:25

    It works because the buttonWorking_Click async code (DelayAsync as well as the async lambda passed to Task.Run) does not have a current SynchronizationContext, whereas the buttonDeadlock_Click async code (DelayAsync) does. You can observe the difference by running in the debugger and watching SynchronizationContext.Current.

    I explain the details behind the deadlock scenario in my blog post Don't Block on Async Code.

提交回复
热议问题