Click here to Skip to main content
15,893,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I have a function like that

// initial some thread
Thread td1 = new ...
Thread td2 = new ...
Thread td3 = new ...

// start those thread
td1.Start();
td2.Start();
td3.Start();

// wait for all thread finished.
???? => what is solution for this?

// this action have to wait all threads finish before be started.
doNextAction();


Could you show me how to be sure all child thread finished?
Thank so much,
TuanNM
Posted

See Thread.Join[^].

In your example:
td1.Join();
td2.Join();
td3.Join();
 
Share this answer
 
v2
Comments
TuanNGUYEN 15-Feb-12 10:56am    
Thanks.
You could use Thread.Join, but that will block until the thread is indeed finished.
You could poll Thread.IsAlive, but that isn't a brilliant idea either.
I would have a ThreadFinished event handler, in which I checked all three threads IsAlive property. When they are all done, you can continue.
 
Share this answer
 
Comments
TuanNGUYEN 15-Feb-12 10:56am    
Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900