when should I use ConfigureAwait(true)

后端 未结 5 2053
灰色年华
灰色年华 2020-12-29 01:55

Has anyone come across a scenario for using ConfigureAwait(true)? Since true is the default option I cannot see when would you ever use it.

5条回答
  •  太阳男子
    2020-12-29 02:24

    If you are using Azure's Durable Functions, then you must use ConfigureAwait(true) when awaiting your Activity functions:

    string capture = await context.CallActivityAsync("GetCapture", captureId).ConfigureAwait(true);
    

    Otherwise you will likely get the error:

    "Multithreaded execution was detected. This can happen if the orchestrator function code awaits on a task that was not created by a DurableOrchestrationContext method. More details can be found in this article https://docs.microsoft.com/en-us/azure/azure-functions/durable-functions-checkpointing-and-replay#orchestrator-code-constraints.".

    Further information can be found here.

提交回复
热议问题