await not using current SynchronizationContext

前端 未结 2 901
隐瞒了意图╮
隐瞒了意图╮ 2021-01-14 02:52

I\'m getting confusing behavior when using a different SynchronizationContext inside an async function than outside.

Most of my program\'s code uses a custom Synchro

2条回答
  •  无人共我
    2021-01-14 03:13

    I would expect your code to work, but there are a few possible reasons why it's not:

    1. Ensure your SynchronizationContext is current when it executes its continuations.
    2. It's not strictly defined when the SynchronizationContext is captured.
    3. The normal way to run code in a SynchronizationContext is to establish the current one in one method, and then run another (possibly-asynchronous) method that depends on it.
    4. The normal way to avoid the current SynchronizationContext is to append ConfigureAwait(false) to all tasks that are awaited.

提交回复
热议问题