0311_C#队列Queue

2017-04-18  本文已影响0人  Asa_Guo
 class Program
    {
        static Queue<string> q = new Queue<string>();
        static void Main(string[] args)
        {
            // 1.创建分线程,执行出列
            // 向数据库中保存数据
            Thread th = new Thread(new ThreadStart(printQueue));
            th.Start();

            // 2.主线程,执行入列
            // 从Web接口获取数据,加入到队列,待保存
            while (true)
            {
                string str = Console.ReadLine();
                q.Enqueue(str);
            }
            Console.Read();
        }

        static private void printQueue()
        {
            while (true)
            {
                if (q.Count > 0)
                {
                    string str = q.Dequeue();
                    Console.WriteLine(str);
                }
            }
        }
    }
上一篇下一篇

猜你喜欢

热点阅读