[英]Stop program execution until threads complete
I have a console application that inits 4 theads to perform a long task. 我有一个控制台应用程序,在4个theads中执行一项长任务。 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?
有没有办法阻止程序执行,让线程完成他们的工作?
Threading.Thread.Join is what you are looking for. Threading.Thread.Join就是你要找的。
Load your application after those threads are joined eg: 在连接这些线程后加载您的应用程序,例如:
Thread1.join();
Thread2.join();
Thread3.join();
Thread4.join();
startApplication();
If you could provide me in more detail i can help you better. 如果你能提供更详细的信息,我可以帮助你。
Depending upon how you're starting the 4 threads then WaitHandle.WaitAll might be a good place to start... 根据你如何开始4个线程,WaitHandle.WaitAll可能是一个好的开始......
http://msdn.microsoft.com/en-us/library/z6w25xa6.aspx http://msdn.microsoft.com/en-us/library/z6w25xa6.aspx
Thread.Join就是你想要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.