Is ConfigureAwait(false) required on all levels of the async chain when no real I/O call is involved?

前端 未结 2 1787
既然无缘
既然无缘 2021-01-20 03:10

Implementing a reusable adaptor type of library on top of Azure Document Db Client SDK.

The library can run anywhere, not only in an ASP.NET Core web service, but i

2条回答
  •  太阳男子
    2021-01-20 03:27

    The continuations unlike a synchronous code which precedes an await call, are executed in context of different call-stack calls. In particular they are scheduled for execution as separate delegates and there is no call-stack relationship between them. So specifying ConfigureAwait(false) for very last continuation execution will take effect only for this specific continuation, other continuations will still execute using their individual scheduling configuration. That is, if your goal is to ensure not capturing a synchronization context by any continuation in your library (in order to prevent potential dead locks or any other reason) then you should configure all await calls which have continuations with ConfigureAwait(false).

提交回复
热议问题