ACP
ACP

Reputation: 35268

When should one use asynchronous controller in asp.net mvc 2?

Thus far worked with asp.net mvc1 and just started with asp.net mvc2..... what are good candidates for executing a controller asynchronously? Should i use it for long running process or some background processing? What are the pros and cons choosing asynchronous controller in asp.net mvc 2? Any suggestion...

Upvotes: 6

Views: 2432

Answers (2)

XWiśniowiecki
XWiśniowiecki

Reputation: 1843

If your controller's method is calling some other system for example query DB or external resources with HTTP and operation lasts long then you should implement those methods as async to let the thread used to doing that be released from waiting on the results and used to service other requests. Our application is getting threads from ThreadPool and number of them is limited. Considering that limitation and the situations of having lot of application users and also long-time queries for data is it very easy to see how important it is.

Upvotes: 0

LondonBasedEngineer
LondonBasedEngineer

Reputation: 665

Only use async if the operation is IO bound. A good example would be aggregating RSS feeds from multiple servers and then displaying them in a webpage.

See:

for a good overview of asynchronous controllers.

And for more in-depth but non-MVC specific info: http://blogs.msdn.com/tmarq/archive/2010/04/14/performing-asynchronous-work-or-tasks-in-asp-net-applications.aspx

Upvotes: 5

Related Questions