oscilatingcretin
oscilatingcretin

Reputation: 10959

VB.NET 4.0: Looking to execute multiple threads, but wait until all threads are completed before resuming

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?

Upvotes: 1

Views: 1252

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1503899

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.Invoke which will invoke each of a collection of Action delegates 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 Task and use Task.WaitAll to wait for everything to finish.

Upvotes: 4

Related Questions