I just had a new, last-minute idea on to take on a task, so I am running to StackExchange for quick help.
What I want to do is execute a series of methods right in a row, each in their own threads. I want the application to wait until all of these threads are completed, after which the program will resume. It also has to use managed threading (thread pool).
What quick examples could you provide to help me along the way? If it’s too complex, what things should I know about so that I can Google it on my own?
If you’re using .NET 4, it would be best to use the Task Parallel Library.
The simplest approach in this case sounds like
Parallel.Invokewhich will invoke each of a collection ofActiondelegates using an appropriate degree of parallelism, and waiting until they’ve all completed before returning.If you need more fine-grained control than that, you can start each as a separate
Taskand useTask.WaitAllto wait for everything to finish.