I’ve been coding a Multithreading Application to solve mazes. I start a new thread from my Program Class, Main() method, to begin solving the maze. He will then call a static method to create a new thread if he finds a bifurcation. How can I wait for all the threads running in the background to finish, in order to, for example display a message of completion?
This is an eskeleton of what I’m trying to do:
var explorer = new Explorer(/*Some arguments*/);
var thread = new Thread(explorer.Explore) {Name = "Thread 0"};
thread.Start();
//Thread_0_and_Threads_he_generates_through_static_class.Join()
Console.WriteLine("I'm done bro.");
Console.ReadKey();
Is there a way to do this? Honestly, first time working with Multithreading in this way, so I apologize for the poor code. Any other information I’ll be more than happy to provide. Thanks in advance.
Perhaps Thread.Join() is what you’re looking for?
you also might find this article usefull.