美文网首页
0311_C#队列Queue

0311_C#队列Queue

作者: Asa_Guo | 来源:发表于2017-04-18 08:40 被阅读0次
     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);
                    }
                }
            }
        }
    

    相关文章

      网友评论

          本文标题:0311_C#队列Queue

          本文链接:https://www.haomeiwen.com/subject/nbqzgttx.html