How to run an async task without having to wait for the result in the current function / thread?

Is there a 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   
}  
+3
source share
2 answers

Grab Taskand wait for it after execution OtherWork:

async Task SomeTask()  
{  
   var childTask = ChildTask();

   //Then something we want to be done without waiting till "Child Task" finished  
   OtherWork();  
   await childTask;
}  
+6
source

You should not wait for asynchronous Task. If you donโ€™t await, itโ€™s because you donโ€™t care whether it is completed successfully or not (shooting and slaughter).

If you do this, you should not use the keyword asyncin your method / delegate signatures.

+3
source

Source: https://habr.com/ru/post/1684974/


All Articles