Question

When is it absolutely necessary for a controller to be async? Should all controllers be async or is it bad practice to make all of them async unless it is necessary. Just looking for some general guidelines.

Was it helpful?

Solution

It's never absolutely necessary for a controller to be async. Calls to controller methods will eventually return. However, it might be desirable to hand off a long-running task to a thread, so that the web server is not blocked for a long period of time.

I wouldn't bother making every controller asynchronous. There is some overhead involved in creating new threads; making every controller asynchronous might actually slow things down.

Use asynchronous action methods for long-running, non-CPU bound requests. This avoids blocking the Web server from performing work while the request is being processed. A typical use for the AsyncController class is long-running Web service calls.

http://msdn.microsoft.com/en-us/library/ee728598(v=vs.100).aspx

Licensed under: CC-BY-SA with attribution
scroll top