Simplest way to run three methods in parallel in C#

前端 未结 5 1340
一向
一向 2020-12-04 14:01

I have three methods that I call to do some number crunching that are as follows

results.LeftFront.CalcAi();  
results.RightFront.CalcAi();  
results.RearSus         


        
5条回答
  •  自闭症患者
    2020-12-04 14:35

    var task1 = SomeLongRunningTask();
    var task2 = SomeOtherLongRunningTask();
    
    await Task.WhenAll(task1, task2);
    

    The benefit of this over Task.WaitAll is that this will release the thread and await the completion of the two tasks.

提交回复
热议问题