Async MultiThreading

M

michaeltorus

Hi

If I start a bunch of asynchronous threads using a deletegate.beingInvoke, what is the prefered way to have the main thread wait until all threads have returned before continuing ...

I simply don't like the idea of an exmpty while loop, and even worse a while loop with a Thread.Sleep statement in it ....

At the moment I use a private int to count how many Threads I start, and decrement it each time a thread finishes (using locking of course) .... it all works fine but I just don't feel this is the best way to do it ....

I thought of using n event, but something still has to tell the main thread to wait until the event is fired ????

Thanks

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,573
Members
45,046
Latest member
Gavizuho

Latest Threads

Top