Пример #1
0
        public static void test()
        {
            Producer_Consumer_Queue wt = new Producer_Consumer_Queue();

            wt.Limt          = 10;
            wt.MaxRetryCount = 3;
            wt.IsLongRunning = false;
            wt.IsIntensive   = true;
            int i = 0;

            while (true)
            {
                i++;
                Thread.Sleep(500);
                var num    = i;
                var action = new Action(() =>
                {
                    Thread.Sleep(1000);
                    Console.WriteLine("消费消息:" + num);
                });
                wt.Enqueue(action);
                if (i > 20)
                {
                    break;
                }
            }
            while (true)
            {
                var input  = Console.ReadLine();
                var action = new Action(() =>
                {
                    Thread.Sleep(2000);
                    Console.WriteLine("消费消息:" + input);
                });
                wt.Enqueue(action);
            }
        }