If I just return a view, is there performance diffrence to return it from Task?
[HttpGet]
public Task<ViewResult> Index()
{
return Task.FromResult(View());
}
[HttpGet]
public ViewResult Index()
{
return View();
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In your case, the
Taskversion is likely to be slower, because you’re just adding overhead ofTaskwith no benefit. Returning aTaskmakes sense when you can take advantage ofasync–await, that is, if you’re actually performing some action that can be made asynchronous in your method.