是“异步"吗?异步ASP.NET MVC 4操作名称中是否需要后缀? [英] Is the "Async" suffix required in the name of an async ASP.NET MVC 4 action?
本文介绍了是“异步"吗?异步ASP.NET MVC 4操作名称中是否需要后缀?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出以下ASP.NET MVC 4控制器操作:
Given the following ASP.NET MVC 4 controller action:
public async Task<ActionResult> FooAsync()
{
using (var httpClient = new HttpClient())
{
var responseMessage = await httpClient.GetAsync("http://stackoverflow.com");
string response = await responseMessage.Content.ReadAsStringAsync();
return Content(response);
}
}
是否需要将异步"后缀放在 FooAsync 中才能使操作异步运行?
Do I need to put the "Async" suffix in FooAsync for the action to be run asynchronously?
推荐答案
否,这不是必需条件.
按照惯例,您将异步"附加到具有以下内容的方法的名称中: 异步或异步修饰符.
By convention, you append "Async" to the names of methods that have an Async or async modifier.
您可以忽略事件,基类或接口的约定 合同建议使用其他名称.例如,您不应该重命名 常见事件处理程序,例如Button1_Click.
You can ignore the convention where an event, base class, or interface contract suggests a different name. For example, you shouldn’t rename common event handlers, such as Button1_Click.
源: 查看全文