相关疑难解决方法(0)

如果我不关心它的返回值,我应该等待“异步任务”函数吗?

如果不返回任何内容,我是否需要等待异步任务函数?这是否会导致以下代码被包装在委托中并在异步任务函数返回后执行?

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");
}
Run Code Online (Sandbox Code Playgroud)

在上面的示例中,如果我在 Test() 中等待 DoSomethingAsync(),是否会导致以下代码 Console.WriteLine 被包装在委托中并仅在异步任务完成时延迟执行?

c# asynchronous

7
推荐指数
2
解决办法
4374
查看次数

标签 统计

asynchronous ×1

c# ×1