Is it advantageous to use ConfigureAwait(false) in a library that directly returns a Task from a call to another library?

后端 未结 2 1387
[愿得一人]
[愿得一人] 2021-02-15 19:35

Follow-up to this question. I have a library with many async methods that thinly wrap HttpClient. Effectively they just do some setup and directly return the Task r

2条回答
  •  终归单人心
    2021-02-15 19:57

    No, ConfigureAwait as its name suggests, configures the await. If you don't need to await then you don't need to configure it.

    There's no added value in adding async-await just to use ConfigureAwait as it only affects your method and not the calling method. If the caller needs to use ConfigureAwait they will do so themselves.

    Having an async method instead of a simple Task-returning method is a valid choice for many reasons (e.g. exception handling), and it will require using ConfigureAwait but ConfigureAwait is not a good reason for doing that by itself.

提交回复
热议问题