如何运行异步任务而无需等待当前函数/线程的结果? [英] How to run async task without need to await for result in current function/thread?
本文介绍了如何运行异步任务而无需等待当前函数/线程的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有机会避免等待? 我们想要的例如:
Is there any chance to avoid waiting? What we want for example:
async Task SomeTask()
{
await ChildTask();
//Then something we want to be done without waiting till "Child Task" finished
OtherWork();
}
async Task ChildTask()
{
//some hard work
}
推荐答案
捕获Task
,然后在OtherWork
完成后等待它:
Capture the Task
and then await it after OtherWork
is done:
async Task SomeTask()
{
var childTask = ChildTask();
//Then something we want to be done without waiting till "Child Task" finished
OtherWork();
await childTask;
}
这篇关于如何运行异步任务而无需等待当前函数/线程的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文