I have a method that is firing off threads to do some work. There will be 2 threads running asynchronously for a period of time, and when their callback method get’s called, the callback fires off another thread until all the work has been finished. How do I make my method wait for all these threads to finish and be fired off?
Share
Interlocked.Increment an initially zeroed counter just before starting any thread. Interlocked.Decrement a counter in every thread just before exit/loopback. If any thread decrements the counter to zero, Set() an AutoResetEvent. WaitOne() on the AutoResetEvent.
Rgds,
Martin