11

I checked the System.Web.Mvc.AsyncController in MVC 4.0, it has the comment "Provided for backward compatibility with ASP.NET MVC 3." does this mean there is a new implementation of async controller in MVC 4? what's the correct way in MVC 4.0 enable async a controller in order to put the I/O intense operations in other thread pool other than IIS request thread pool?

1 Answer 1

14

Starting from ASP.NET MVC 4, you can now use the System.Web.Mvc.Controller class as the base class and leverage the TAP (Task-based Asynchronous Pattern):

public async Task<ViewResult> Index() { 

     return View(await GetThingsAsync());
}

Note that you don't have to use async and await keywords which come with C# 5.0 but they make asynchronous programming much, much easier and more maintainable.

Have a look at the following articles:

Sign up to request clarification or add additional context in comments.

2 Comments

Doesn't async and await come with C# 4.5, not 5.0?
@Spook there's no C# 4.5: en.wikipedia.org/wiki/C_Sharp_(programming_language)#Versions async/await language support came with C# 5.0 and it also needs .NET 4.5. You may use .NET 4.0 and leverage the async/await language features with a NuGet package from the BCL team: nuget.org/packages/Microsoft.Bcl.Async

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.