【发布时间】:2015-12-16 16:03:21
【问题描述】:
举个例子:
void Main() { Test().Wait(); }
async Task Test()
{
Console.WriteLine("Test A");
await AsyncFunction();
// It doesn't matter where the await is in AsyncFunction, it will always wait for the function to complete before executing the next line.
Console.WriteLine("Test B");
}
async Task AsyncFunction()
{
Console.WriteLine("AsyncFunction A");
await Task.Yield();
Console.WriteLine("AsyncFunction B");
}
在任何情况下都不会在“AsyncFunction B”之前显示“Test B”
Test() 中的 await 语句不只是等待 Task.Yield() 完成恢复,而是等待整个 AsyncFunction 完成?
【问题讨论】:
标签: c# .net asynchronous async-await task-parallel-library