C#隊列Queue多線程用法實例
更新時間:2015年05月16日 12:27:46 作者:永遠(yuǎn)愛好寫程序
這篇文章主要介紹了C#隊列Queue多線程用法,實例分析了隊列的相關(guān)使用技巧,需要的朋友可以參考下
本文實例講述了C#隊列Queue多線程用法。分享給大家供大家參考。具體分析如下:
這里展示一個例子,供學(xué)習(xí)使用:
private void button_測試Queue結(jié)合多線程_Click(object sender, EventArgs e) { Console.WriteLine("初始化隊列"); queue = new Queue<string>(); string[] cars = new string[]{"寶馬","奔馳", "奧迪","東風(fēng)","勞斯萊斯"}; foreach (string str in cars) { queue.Enqueue(str); Console.WriteLine("入隊列-{0}", str); } Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Red; Thread th = new Thread(new ThreadStart(printQueue)); th.IsBackground = true; //后臺運(yùn)行,主窗體關(guān)閉后,可退出程序 th.Start(); } private void printQueue() { while (true) { if (queue.Count > 0) { Console.WriteLine("出隊列-{0}", queue.Dequeue()); } } }
運(yùn)行結(jié)果
希望本文所述對大家的C#程序設(shè)計有所幫助。
相關(guān)文章
非常實用的C#字符串操作處理類StringHelper.cs
這篇文章主要為大家詳細(xì)介紹了非常實用的C#字符串操作處理類StringHelper.cs,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-07-07