示例#1
0
        public void TestPost()
        {
            var thread = new WorkerThread("Test", "TestPost", ThreadPriority.BelowNormal, 10);

            Assert.IsFalse(thread.IsIdle);
            Assert.AreEqual(0, thread.QueueLength);
            Assert.AreEqual(0, counter);

            thread.Post(IncrementCounter, this, null);
            thread.Post(IncrementCounter, this, null);
            thread.Post(IncrementCounter, this, null);
            Assert.IsFalse(thread.IsIdle);
            Assert.AreEqual(3, thread.QueueLength);
            Assert.AreEqual(0, counter);

            thread.Start();
            while (!thread.IsIdle)
            {
                Thread.Sleep(1);
            }

            Assert.IsTrue(thread.IsIdle);
            Assert.AreEqual(0, thread.QueueLength);
            Assert.AreEqual(3, counter);

            thread.Stop();
        }