Exemplo n.º 1
0
        public void CreateAndUseAgentQueue()
        {
            AgentQueue <Counter> queue = new AgentQueue <Counter>(1);

            Thread thread = new Thread(new ThreadStart(delegate() { queue.Enqueue(c => { c.Increment(); }); }));

            thread.Start();

            Action <Counter> action = queue.Dequeue();

            Assert.IsNotNull(action);

            Counter counter = new Counter();

            action(counter);
            Assert.AreEqual(1, counter.Count);
        }
Exemplo n.º 2
0
        public void CreateAndUseAgentQueueTenTimes()
        {
            AgentQueue <Counter> queue = new AgentQueue <Counter>(5);

            Thread thread = new Thread(new ThreadStart(delegate() { for (int k = 1; k <= 10; k++)
                                                                    {
                                                                        queue.Enqueue(c => { c.Increment(); });
                                                                    }
                                                       }));

            thread.Start();

            Counter counter = new Counter();

            for (int j = 1; j <= 10; j++)
            {
                Action <Counter> action = queue.Dequeue();
                Assert.IsNotNull(action);
                action(counter);
                Assert.AreEqual(j, counter.Count);
            }
        }