Пример #1
0
        public void CancellationTest()
        {
            var resultingList = new ConcurrentBag <int>();

            SetupTest((item) => { Thread.Sleep(500); resultingList.Add(item); });

            queue.Add(1);

            Thread.Sleep(100);

            // вызываем Cancel вместо вызова queue.CompleteAdding();
            thread.Cancel();

            Thread.Sleep(1000);

            Assert.AreEqual(1, resultingList.Single());
            Assert.AreEqual(true, isThreadCompleted);
            Assert.IsNull(threadException);
        }