When to use an Async Controller in ASP.NET MVC

Edit
I have known there is Async Controller in .NET MVC for sometime, however, I never tried to see why it is created and how to decide using it or not.

In short, using async controller would make the thread in the application pool in IIS being used work more efficiently. However, the code will be not as straightforward as non-async controller.

In determining whether an async controller should be use, here are some guidelines from MSDN:

"In general, use synchronous pipelines when the following conditions are true:

  • The operations are simple or short-running.
  • Simplicity is more important than efficiency.
  • The operations are primarily CPU operations instead of operations that involve extensive disk or network overhead. Using asynchronous action methods on CPU-bound operations provides no benefits and results in more overhead.

In general, use asynchronous pipelines when the following conditions are true:

  • The operations are network-bound or I/O-bound instead of CPU-bound.
  • Testing shows that the blocking operations are a bottleneck in site performance and that IIS can service more requests by using asynchronous action methods for these blocking calls.
  • Parallelism is more important than simplicity of code.
  • You want to provide a mechanism that lets users cancel a long-running request."

Details: Using an Asynchronous Controller in ASP.NET MVC

When to use an Async Controller in ASP.NET MVC When to use an Async Controller in ASP.NET MVC Reviewed by DF on 5:45:00 PM Rating: 5
©DF. Powered by Blogger.