public void StartAllThreads(int runningTimeout)
        {
            isFinishing = false;
            StartAllThreadsAtOnce();

            AutoResetEventEx timout = new AutoResetEventEx(false);
            Thread stopperThread = FlagIfEndingPrematurely(timout);
            stopperThread.Start();

            timout.WaitOne(runningTimeout, false);

            stopperThread.Abort();
            isFinishing = true;
            StopAllRunningThreads();
        }
 private Thread FlagIfEndingPrematurely(AutoResetEventEx flag)
 {
     Thread t = new Thread(new ThreadStart(delegate
                               {
                                   try
                                   {
                                       while (true)
                                       {
                                           if (ThreadAction.AllCanceled)
                                           {
                                               Console.WriteLine("Ending Prematurely");
                                               flag.Set();
                                               return;
                                           }
                                           Thread.Sleep(100);
                                       }
                                   }
                                   catch (ThreadAbortException e)
                                   {
                                       Thread.ResetAbort();
                                   }
                               }));
     return t;
 }