What is the advantage of using async with MVC5?

后端 未结 3 1616
臣服心动
臣服心动 2020-11-28 02:05

What is the difference between:

public ActionResult Login(LoginViewModel model, string returnUrl)
{
    if (ModelState.IsValid)
    {
        IdentityResult          


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-28 02:41

    Normally, a single HTTP request would be handled by a single thread, completely removing that thread from the pool until a response is returned. With the TPL, you are not bound by this constraint. Any request that come in starts a continuation with each unit of computation required to calculate a response able to execute on any thread in the pool. With this model, you can handle many more concurrent requests than with standard ASP.Net.

    If it is some new task that will be spawned, or not, and if it should be awaited or not. Always think about those 70 ms, which is approx. the max. time that any method call should take. If its longer, then your UI will most probably not feel very responsiveness.

提交回复
热议问题