C# TPL how to know that all tasks are done?

前端 未结 3 874
失恋的感觉
失恋的感觉 2021-02-06 07:16

I have the Loop which generates tasks.

Code:

Task task = null;
foreach (Entity a in AAAA)
{
  // create the task 
  task = new Task(() => {
    myMeth         


        
3条回答
  •  你的背包
    2021-02-06 07:51

    I f you replace this with a

     Parallel.ForEach(...,  () => myMethod(a), ...)
    

    Then you get an automatic Wait on all tasks at the end of the ForEach.

    And maybe run the ForEach from a separate Task.

提交回复
热议问题