Reputation: 9073
I have understood the reason of async and await in a WPF application: This permit to the main UI thread not wasting time. The user can interact with UI whereas an I/O operation is waiting at the same time.
What i do not understand is why we see the same concept in ASP.Net Core MVC 2.0. WebMethods [HttpGet], [HttpPost] should wait anyway before rendering the page...
Thanks
Upvotes: 0
Views: 259
Reputation: 883
It frees up the cpu to service other requests to your controllers rather than busy wait on whatever async operations you are doing. This answer has a pretty good analogy to help explain:
Think of it like getting on a bus, there's five people waiting to get on, the first gets on, pays and sits down (the driver serviced their request), you get on (the driver is servicing your request) but you can't find your money; as you fumble in your pockets the driver gives up on you and gets the next two people on (servicing their requests), when you find your money the driver starts dealing with you again (completing your request) - the fifth person has to wait until you are done but the third and fourth people got served while you were half way through getting served. This means that the driver is the one and only thread from the pool and the passengers are the requests.
Without an async controller, the passengers behind you would have to wait ages while you looked for your money, meanwhile the bus driver would be doing no work.
Upvotes: 2