public void Abort() { lock (workQueue) { if (activeThreads > 0) { // flag active workers to stop; last will reset the flag aborting = true; } // to avoid non-determinism, always clear the queue workQueue.Clear(); } }