Running multiple async tasks and waiting for them all to complete

后端 未结 9 1493
渐次进展
渐次进展 2020-11-22 13:36

I need to run multiple async tasks in a console application, and wait for them all to complete before further processing.

There\'s many articles out there, but I see

9条回答
  •  失恋的感觉
    2020-11-22 14:16

    You could create many tasks like:

    List TaskList = new List();
    foreach(...)
    {
       var LastTask = new Task(SomeFunction);
       LastTask.Start();
       TaskList.Add(LastTask);
    }
    
    Task.WaitAll(TaskList.ToArray());
    

提交回复
热议问题