Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use AsyncController at ASP.NET MVC 4?

This class has this description:

Provided for backward compatibility with ASP.NET MVC 3.

And the source is just:

public abstract class AsyncController : Controller
{
}

I can´t find any documentation about deprecation of this class at MSDN. Should I replace uses of AsyncController to Controller?

like image 315
Felipe Pessoto Avatar asked Dec 05 '12 10:12

Felipe Pessoto


People also ask

Should I use async controller actions?

async actions help best when the actions does some I\O operations to DB or some network bound calls where the thread that processes the request will be stalled before it gets answer from the DB or network bound call which you just invoked.

When would you use asynchronous actions?

Calling an asynchronous controller action will not block a thread in the thread pool. Asynchronous actions are best when your method is I/O, network-bound, or long-running and parallelizable. Another benefit of an asynchronous action is that it can be more easily canceled by the user than a synchronous request.

What is the use of async controllers in MVC?

The asynchronous controller enables you to write asynchronous action methods. It allows you to perform long running operation(s) without making the running thread idle. It does not mean it will take lesser time to complete the action.

Why we use async and await in MVC?

Async, Await And Asynchronous Programming In MVC. Async keyword is used to call the function/method as asynchronously. Await keyword is used when we need to get result of any function/method without blocking that function/method.


1 Answers

Should I use AsyncController at ASP.NET MVC 4?

No.

Should I replace uses of AsyncController to Controller?

Yes, asynchronous actions are implemented in new way in asp.net-mvc 4, using Task Class

The ASP.NET MVC 4 Controller class in combination .NET 4.5 enables you to write asynchronous action methods that return an object of type Task. The .NET Framework 4 introduced an asynchronous programming concept referred to as a Task and ASP.NET MVC 4 supports Task. Tasks are represented by the Task type and related types in the System.Threading.Tasks namespace. The .NET Framework 4.5 builds on this asynchronous support with the await and async keywords that make working with Task objects much less complex than previous asynchronous approaches. The await keyword is syntactical shorthand for indicating that a piece of code should asynchronously wait on some other piece of code. The async keyword represents a hint that you can use to mark methods as task-based asynchronous methods. The combination of await, async, and the Task object makes it much easier for you to write asynchronous code in .NET 4.5. The new model for asynchronous methods is called the Task-based Asynchronous Pattern (TAP). This tutorial assumes you have some familiarity with asynchronous programing using await and async keywords and the Task namespace.

More reading at Using Asynchronous Methods in ASP.NET MVC 4

like image 178
archil Avatar answered Oct 09 '22 07:10

archil