Thread.Join();を使用した簡単な例。
Thread t1 = new Thread(new ThreadStart(delegate()
{
System.Threading.Thread.Sleep(2000);
}));
Thread t2 = new Thread(new ThreadStart(delegate()
{
System.Threading.Thread.Sleep(4000);
}));
t1.Start();
t2.Start();
t1.Join();
t2.Join();
EDITは待ちを使用して別の3exampleは、ハンドル:は、他の回答に加えて
ManualResetEvent[] waitHandles = new ManualResetEvent[]{
new ManualResetEvent(false),
new ManualResetEvent(false)
};
Thread t1 = new Thread(new ParameterizedThreadStart(delegate(object state)
{
ManualResetEvent handle = (ManualResetEvent)state;
System.Threading.Thread.Sleep(2000);
handle.Set();
}));
Thread t2 = new Thread(new ParameterizedThreadStart(delegate(object state)
{
ManualResetEvent handle = (ManualResetEvent)state;
System.Threading.Thread.Sleep(4000);
handle.Set();
}));
t1.Start(waitHandles[0]);
t2.Start(waitHandles[1]);
WaitHandle.WaitAll(waitHandles);
Console.WriteLine("Finished");
も参照してください:http://stackoverflow.com/questions/540078/wait-for-pooled-threads-to-complete –