Пример #1
0
        public void BasicThreadQueue()
        {
            ThreadDispatcher dispatcher = new ThreadDispatcher();

            // test CreateQueue - succeeds
            IActionQueue queue = dispatcher.CreateQueue();

            Assert.IsNotNull(queue);

            // test queuing an action
            counter = 0;
            queue.Enqueue(() => { IncrementCounter(Thread.CurrentThread.ManagedThreadId); });
            queue.Enqueue(() => { IncrementCounter(Thread.CurrentThread.ManagedThreadId); });

            // spin until counter updates
            while (counter < 2)
            {
                Thread.Sleep(0);
            }

            // check if a thread failed
            Assert.IsFalse(failed);

            // close things out
            dispatcher.Dispose();
        }