【发布时间】:2011-09-11 08:40:54
【问题描述】:
在一个 win 表单应用程序中,我有一个线程数组,它们是这样启动的:
bool stop = false;
Thread[] threads = new Thread[10];
for (int i = 0; i < threads.Length; i++)
threads[i] = new Thread(new ThreadStart(Job));
// How to make sure all threads have exited, when the boolean = false
void Job()
{
while (!stop)
// Do something
}
现在,如果用户按下 STOP,stop 的布尔值将设置为 true,因此线程一个接一个地退出 Job 方法。如何确保所有线程都已退出?
注意:我的情况需要传统线程,TaskLibrary 不适合我的情况。
【问题讨论】:
标签: c# multithreading synchronization