What is the difference between public async System.Threading.Tasks.TaskActionResult Index () and public ActionResult Index ()? [duplicate]

1

Follow the code:

Example 1:

public async System.Threading.Tasks.Task<ActionResult> Index()
{

   return View();
}

Example 2:

public ActionResult Index()
{
   return View();
}

Please explain the difference between the 2 in as much detail as possible with get and post .

    
asked by anonymous 07.01.2017 / 01:00

2 answers

2

The difference is that the former can be executed asynchronously, so it will not crash the application if the execution of the method takes too long.

In general you will have a await within this method calling another asynchronously.

As far as I know, it does not make a difference between the request methods.

The question does not give much context, so I can not answer much more than that.

    
07.01.2017 / 01:10
0

In case it will not make a difference and you should not compile because your method does nothing asynchronous.

If you make an asynchronous call in your code, the example 1 signature is required:

public async System.Threading.Tasks.Task<ActionResult> Index()
{
    await MetodoAsync();
    return View();
}

public async Task MetodoAsync()
{
    // faz algo assíncrono
}

In practice, all methods that do something asynchronous need to be marked as async and should return a Task .

In the case of Controller's public methods, this allows them to be executed asynchronously by the framework.

    
09.01.2017 / 22:43