One simple option is to store links to all the threads you create, and then join them when you are done:
Thread[] threads = new Thread[8];
for (int i = 0; i < 8; i++)
{
doImages = new DoImages(this, TCPPORT + i);
var thread = new Thread(doImages.ThreadProc);
threads[i] = thread;
thread.Name = "Imaging";
var param = (i + 1).ToString();
thread.Start(param);
}
for (int i = 0; i < 8; i++)
{
threads[i].Join();
}
This will wait for all threads to complete before the application completes.
source
share