I'm trying to get my head around asynchronous programming in C# 5 and the question that I keep asking myself is why not use it all the time (for ASP.NET MVC 4 or Web API), like the node.js guys are doing?
Is there any disadvantages (unnecessary overhead) other than the code not as straightforward (which is IMHO a joke since the new syntax is great an easy to understand)?
For the most part, use it everywhere indeed. That is why they turned everything that takes longer than 50 ms into an async call :).
However, it will have the same pitfalls as any async code. Debugging could become trickier. If you begin doing one thing and then it returns to a long task on the UI thread, it could result in false freezing (user was able to move after click, but then later cannot when doing nothing as far as they see it). Etc
If you run it through code that waits for values, then it will act like synchronous code anyway. And, if it hits the cache or some fast action, then it will not run async for efficiency. So, this last point means that even though there is overhead to perform compiler magic in these calls, that magic will not be done if the call is completed already and therefore not worth the overhead.
So, yes, I would say use it just about everywhere :) It is a great step for .NET
UPDATE
If this article is to believed then it only justifies what I am saying. If the call takes less than 50 ms, then it is not and should not be async due to the overhead to write it that way. And, in fact will most often trigger the synchronous action instead of the async one. However, if it is over 50 ms, then you only gain from the async call
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With