【发布时间】:2016-12-15 19:33:15
【问题描述】:
我在看async-await的解释,上面写着
async Task<int> IndexWordsFromAsync(string url)
{
string content = await httpClient.GetStringAsync(url);
int wordCount = AddContentToIndex(content);
return wordCount;
}
int AddContentToIndex(string content)
{
...
}
等价于
Task<int> task = IndexWordsFromAsync(url);
var currentContext = SynchronizationContext.Current;
task.ContinueWith(delegate
{
if(currentContext == null)
RestOfMethod();
else
currentContext.Post(delegate { RegstOfMethod(); }, null);
}, TaskScheduler.Current);
有人可以确认这在多大程度上是正确的?或者你能把我链接到互联网上以这种方式描述async-await 的地方吗?
【问题讨论】:
标签: c# .net asynchronous async-await task