avi
avi

Reputation:

Stop program execution until threads complete

I have a console application that inits 4 theads to perform a long task. I want my program to wait until the threads are complete, and then complete the program execution. Is there a way to stop the program from executing, letting the threads complete their job?

Upvotes: 2

Views: 659

Answers (4)

AZ_
AZ_

Reputation: 21899

Load your application after those threads are joined e.g:

Thread1.join();
Thread2.join();
Thread3.join();
Thread4.join();


startApplication();

If you could provide me in more detail i can help you better.

Upvotes: 2

pauljwilliams
pauljwilliams

Reputation: 19225

Thread.Join is what you want.

Upvotes: 1

Martin Peck
Martin Peck

Reputation: 11564

Depending upon how you're starting the 4 threads then WaitHandle.WaitAll might be a good place to start...

http://msdn.microsoft.com/en-us/library/z6w25xa6.aspx

Upvotes: 1

Pondidum
Pondidum

Reputation: 11637

Threading.Thread.Join is what you are looking for.

Edit: Examples here

Upvotes: 15

Related Questions