If I used this code to create threads, how can I wait for all of these threads to complete before proceeding with the rest of the code? Or is there a different way to do this?
for(int i = 0; i < 25; i ++)
{
Program x = new Program(); // Make temporary
Thread myThread = new Thread(() => x.doSomething(someParameter));
myThread.Start();
}
I want to avoid making a big chunk of code for initializng, creating and joining threads.
Thread myThread1 = new Thread(() => x.doSomething(someParameter));
myThread1.Start();
Thread myThread2 = new Thread(() => x.doSomething(someParameter));
myThread2.Start();
Thread myThread3 = new Thread(() => x.doSomething(someParameter));
myThread3.Start();
myThread1.Join();
myThread2.Join();
myThread3.Join();
This code works but my goal is to avoid doing this 50-100 / n times depending on how many threads I need.