예제 #1
0
        protected override void ConsumerOne()
        {
            int     count = 0;
            Message msg;

            while (true)
            {
                var received = _queue.TryDequeue(out msg);
                if (received)
                {
                    count++;
                    if (msg.Terminate)
                    {
                        break;
                    }
                }
            }

            Console.WriteLine("Consumer received {0:#,#;;0} messages.", count);
        }
        private void ConsumeAndPublish(LockedQueue <Message> @in, LockedQueue <Message> @out, string name)
        {
            int     count = 0;
            Message msg;

            while (true)
            {
                var received = @in.TryDequeue(out msg);
                if (received)
                {
                    count++;
                    @out.Enqueue(msg);

                    if (msg.Terminate)
                    {
                        break;
                    }
                }
            }

            Console.WriteLine("Consumer {0} received {1:#,#;;0} messages.", name, count);
        }
        protected override void ConsumerThree()
        {
            int     count = 0;
            Message msgOne;
            Message msgTwo;

            while (true)
            {
                while (!_consumerOneOut.TryDequeue(out msgOne))
                {
                }
                while (!_consumerTwoOut.TryDequeue(out msgTwo))
                {
                }

                count++;
                if (msgTwo.Terminate)
                {
                    break;
                }
            }

            Console.WriteLine("Consumer three received {0:#,#;;0} joined messages.", count);
        }