Thread[] threads = new Thread[12];
int temp;
//_stopRequest = false;
for (int i = 0; i < threads.Length - 1; i++)
{
temp = i;
threads[temp] = new Thread(new ThreadStart(() => test(test1[temp],"start", temp)));
threads[temp].Start();
//threads[temp].Join();
}
for(int i=0; i<threads.Length-1; i++)
{
threads[i].Join();
}
谁能帮我解释一下吗
最佳答案
不,线程在您调用 Start() 时启动。
如果您在 Start()(注释掉的代码)之后立即调用 Join(),则每个线程都将启动,然后当前线程的执行将停止,直到第一个线程停止。所以它实际上充当了单个线程。
现在的代码是这样的,所有线程都启动,然后当前线程等待所有启动的线程完成。
关于c# - thread.join是否同时启动所有线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32673670/