如何使两个子线程先后依次执行?
Thread t1 = new Thread(new ThreadStart(Method1));
t1.Start();
Thread t2 = new Thread(new ThreadStart(Method2));
t2.Start();
t1 执行完之后t2执行
[解决办法]
private System.Threading.ManualResetEvent mre = new System.Threading.ManualResetEvent(true);
void button_onclick(....)
{
Thread t1 = new Thread(new ThreadStart(Method1));
Thread t2 = new Thread(new ThreadStart(Method2));
mre.Reset();
t1.Start();
mre.WaitOne();
t2.Start();
}
void Method1()
{
....
mre.Set();
}
[解决办法]
依次执行?
ThreadPool.QueueUserWorkItem 线程池
[解决办法]
在线程2的执行函数前面加上一句Thread1变量名.Join();