コード例 #1
0
        public void CurrentThreadOnTest()
        {
            var inCheck  = false;
            var outCheck = false;
            var worker   = new WorkerQueue();

            worker.Queue(() => { inCheck = worker.CurrentThreadOn(); });
            worker.Wait();

            outCheck = worker.CurrentThreadOn();

            Assert.IsTrue(inCheck);
            Assert.IsFalse(outCheck);
        }
コード例 #2
0
        public void QueueTest()
        {
            var sequence = 0;
            var worker   = new WorkerQueue();

            worker.Queue(() => { Assert.AreEqual(0, sequence); Thread.Sleep(100); ++sequence; });
            worker.Queue(() => { Assert.AreEqual(1, sequence); Thread.Sleep(10); ++sequence; });
            worker.Queue(() => { Assert.AreEqual(2, sequence); Thread.Sleep(0); ++sequence; });
            worker.Queue(() => { Assert.AreEqual(3, sequence); Thread.Sleep(50); ++sequence; });
            worker.Queue(() => { Assert.AreEqual(4, sequence); Thread.Sleep(150); ++sequence; });
            worker.Queue(() => { Assert.AreEqual(5, sequence); Thread.Sleep(1); ++sequence; });
            worker.Wait();

            Assert.AreEqual(6, sequence);
        }
コード例 #3
0
        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);
        }