i have a listoddata and a list of thread in main thread .i am passing each element data of list to corresponding thread.want to main thread to wait untill all of thread are executed.
for (int i = 0; i < listOfThread.Count; i++)
{
listOfThread[i].Join();
}
// code after all of thread completes its work
//code block2
but after first iteration of this loop main thread will not be executed.and if any thread 0 is completed .code block will be executed. which i dont want.
This is a perfectly valid way to
joinon multiple threads. If you wait on all the threads, even sequentially, it will be just fine. It won’t have to wait on threads that are already complete. If a thread is still running, it will wait until that thread is complete.