I have an array of threads, and I want to Join them all with a timeout (i.e. see if they have all finished within a certain timeout). I'm looking for something equivalent to WaitForMultipleObjects or a way of passing the thread handles into WaitHandle.WaitAll, but I can't seem to find anything in the BCL that does what I want.
I can of course loop through all the threads (see below), but it means that the overall function could take timeout * threads.Count to return.
private Thread[] threads;
public bool HaveAllThreadsFinished(Timespan timeout)
{
foreach (var thread in threads)
{
if (!thread.Join(timeout))
{
return false;
}
}
return true;
}