C# TPL how to know that all tasks are done?
问题 I have the Loop which generates tasks. Code: Task task = null; foreach (Entity a in AAAA) { // create the task task = new Task(() => { myMethod(a); }, Token, TaskCreationOptions.None); task.Start(); } As you can see in each iteration task object has new initialization (..new Task(() =>..) How can I know that all tasks done? 回答1: 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