Sunday, 25 August 2013

Wait for ANY thread to finish, not ALL

Wait for ANY thread to finish, not ALL

I'm starting multiple threads and would like to know when any of then
finishes. I know the following code:
foreach (Thread t in threads)
t.Join();
But it will only wait for all threads together. That's much too late. I
need to know when one thread finishes, even when other threads are still
running. I'm looking for something equivalent to WaitAny only for threads.
But I can't add code to all threads I'm monitoring, so using signals or
other synchronisation objects is not an option.

No comments:

Post a Comment