What is the difference between these two action methods?
public ActionResult Index()
{
var task = new ServiceClient().GetProductsAsync();
return View(task.Result);
}
public async Task<ActionResult> Index()
{
var task = new ServiceClient().GetProductsAsync();
return View(await task);
}
The first one will block an ASP.Net request thread until you get a result from the database.
The second one will release the ASP.Net thread immediately, then grab another one when the result comes in.
Therefore, the second one is more scalable.
Note that this answer assumes that the chain of asynchrony you’re calling is correctly written and ends in actual async socket operations.