<分区>
如果异步任务函数不返回任何内容,我是否需要等待它?这会导致以下代码被包装在委托(delegate)中并在异步任务函数返回后执行吗?
Task DoSomethingAsync()
{
return Task.Run(() =>
{
// Do something, but doesn't return values.
});
}
void Test()
{
DoSomethingAsync(); // should I await?
// Do other things, totally not related to the async function
Console.WriteLine("aaa");
}
在上面的示例中,如果我在 Test() 中等待 DoSomethingAsync(),是否会导致以下代码 Console.WriteLine 被包装在委托(delegate)中并仅在异步任务完成时延迟执行?