【发布时间】:2018-07-08 03:40:57
【问题描述】:
我正在通过一些代码来学习如何使用 Web API。
public async Task<List<TodoItem>> RefreshDataAsync ()
{
// RestUrl = http://developer.xamarin.com:8081/api/todoitems/
var uri = new Uri (string.Format (Constants.RestUrl, string.Empty));
var response = await client.GetAsync (uri);
if (response.IsSuccessStatusCode) {
var content = await response.Content.ReadAsStringAsync ();
Items = JsonConvert.DeserializeObject <List<TodoItem>> (content);
}
}
我找到了这段代码。我只想知道为什么我们使用 Async 和 Await。 正如我所观察到的,当函数被封装为 Async 关键字时,方法主体中的 Await 是强制性的。
【问题讨论】:
-
这不是特定于 web api 的,而是关于为什么应该在 asp.net 中使用 async-await 的更多问题。尝试详细说明这个问题的标题
标签: asp.net-web-api