I recently talked on ThatConference on async on the server side , and I look at this issue in slides.
On the server side, you want to avoid using Task.Run and other constructs that work in line with the thread pool. Whenever possible, support thread pool threads for handling requests.
So, ideally, your repository will have an asynchronous GetAllErrorLogsAsync method, which itself will be asynchronous. If GetAllErrorLogs cannot be asynchronous, you can simply call it directly (removing await Task.Run ).
Since it might take a second to get all the error logs, I want to be able to do other things as soon as I call the GetAllErrorLogs () method.
If you have GetAllErrorLogsAsync , then this can be easily done using Task.WhenAll . However, if GetAllErrorLogs is synchronous, you can do this by doing parallel work in your query (for example, several calls to Task.Run and then Task.WhenAll ).
Parallel code on the server should be greeted with great trepidation. This is acceptable only in a very limited set of scenarios. The whole point of async on the server side is to use fewer threads for each request, and when you start parallelizing, you do the opposite: multiple threads for each request. This is only suitable if you know that your user base is very small; otherwise, you will kill the scalability of your server.
Stephen Cleary Aug 21 '13 at 20:54 on 2013-08-21 20:54
source share