When you have server-side code (i.e. some ApiController
) and your functions are asynchronous - so they return Task
- is it consid
I have some general thoughts about the implementation of Task
:
using
.ConfigureAwait
was introduced in 4.5. Task
was introduced in 4.0. Task.ContinueWith
they do not b/c it was realised context switch is expensive and it is turned off by default.I have got a few posts on the subject but my take - in addition to Tugberk's nice answer - is that you should turn all APIs asynchronous and ideally flow the context . Since you are doing async, you can simply use continuations instead of waiting so no deadlock will be cause since no wait is done in the library and you keep the flowing so the context is preserved (such as HttpContext).
Problem is when a library exposes a synchronous API but uses another asynchronous API - hence you need to use Wait()
/Result
in your code.