Re: How to wait for thread?



"Brett Romero" <account@xxxxxxxxx> wrote in message
news:1155081229.482157.214280@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'd like the main thread to wait until these three threads have
completed their task:

LoadOjbects lo = new LoadOjbects();

lo.thrd1.Start();
lo.thrd2.Start();
lo.thrd3.Start();

while (lo.thrd1.IsAlive || lo.thrd2.IsAlive || lo.thrd3.IsAlive)
{
Thread.Sleep(500);
}

If you just want to wait for all three to end, without regard for the order
in which they end, you can just do:

lo.thrd1.Join();
lo.thrd2.Join();
lo.thrd2.Join();
// You won't get here until all 3 threads have completed
// ...but you can't tell which one completed first
// (nor does it matter).

-cd



.



Relevant Pages


Loading