When should I use Async controllers in ASP.NET MVC?

Changing an ASP.NET MVC synchronous controller ( Controller ) on an asynchronous controller ( AsyncController ) seems like a trivial task, but when will you do it?

Should I do every asynchronous controller regardless of its actions? What are some examples of operations that would be improved when used in an asynchronous controller?

Taking the most trivial example: static html pages. That way, you have the simplest of the controllers that just returns the View from the Index action. If this controller is changed to asynchronous, that is, is it now returned from IndexCompleted ?

+7
source share
2 answers

I recently read this article article . He thinks he summarizes what AsyncController is for.

+8
source

I know this is an old question, but I struggled to get an answer, so here are my two cents.

It’s like if we don’t have a fever, I’ll still take the pill. You should use an Asynch controller if you see a stream puzzle on your web server. IIS web server supports thread pool. Therefore, when any request arrives, it takes a stream from the thread pool. If at the moment all the threads from the pool are used and the request arrives, this request goes into standby mode. This situation is called "Theme Voice." You can also watch this youtube video where I showed how MVC-Threading hunger looks like

http://www.youtube.com/watch?v=wvg13n5V0V0

Web Server Thread Use Diagram

When you create your controller as Asynch, it uses the thread, starts the operation, and moves that thread back to the thread pool, so it can be used for other requests coming into the MVC application. Upon completion of the operation, it draws the stream from the thread pool and displays the view.

+6
source

All Articles