public void ClearTest() { var sequence = 0; var blocker = new ManualResetEvent(false); var worker = new WorkerQueue(); worker.Queue(() => { Assert.AreEqual(0, sequence); blocker.WaitOne(); worker.Clear(); ++sequence; }); worker.Queue(() => { Assert.AreEqual(1, sequence); ++sequence; }); worker.Queue(() => { Assert.AreEqual(2, sequence); ++sequence; }); worker.Queue(() => { Assert.AreEqual(3, sequence); ++sequence; }); worker.Queue(() => { Assert.AreEqual(4, sequence); ++sequence; }); worker.Queue(() => { Assert.AreEqual(5, sequence); ++sequence; }); blocker.Set(); Thread.Sleep(50); Assert.AreEqual(1, sequence); }