日期:2014-05-20  浏览次数:20998 次

我在for循环中创建了多个线程,怎么控制这些线程按照顺序执行?
如题?

------解决方案--------------------
使用全局信号量或者互斥体


------解决方案--------------------
判断
if(线程1运行)
执行线程2
if(线程2运行)
执行线程3
..................
不知还有没有更好的
------解决方案--------------------
例如
bool btag = false;
……
thread th1 = new thread(new ThreadStart(this.Fun1));
thread th2 = new thread(new ThreadStart(this.Fun2));
th1.start();
btag = true;
if(!btag)
{th2.start();}
……
private void Fun1()
{
//TODO
btag = false;
}
------解决方案--------------------
使用Mutex实现也可以