I’m working on an MVC 4 application. I’ve a controller where I make calls to some REST service using the HttpClient class. The controller is a normal controller and the actions are not described with async keyword. Do I get any gain of using PostAsync method of HttpClient class in this case? It’s not a fire and forget call and I need the result returned from the service. The ASP.NET thread is going to be blocked anyway till it get the result and so is there advantage?
I’m working on an MVC 4 application. I’ve a controller where I make calls
Share
You don’t have any advantage in that case. You have to be either all the way async or all the way synchronous.
The single exception I can think of is when you have a singe synchronous MVC action starting off dozens of async, concurrent requests. In that case you burn one thread to coordinate dozens of others. That would be acceptable.
Side note: Async doesn’t apply to most server apps, but in your case it seems like you could benefit from an all-async style solution because you are making a potentially long-running HTTP request. So you might switch to all-async for this one particular MVC action.