时间:2021-05-20
本文实例讲述了C#队列Queue多线程用法。分享给大家供大家参考。具体分析如下:
这里展示一个例子,供学习使用:
private void button_测试Queue结合多线程_Click(object sender, EventArgs e){ Console.WriteLine("初始化队列"); queue = new Queue<string>(); string[] cars = new string[]{"宝马","奔驰", "奥迪","东风","劳斯莱斯"}; 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; //后台运行,主窗体关闭后,可退出程序 th.Start();}private void printQueue(){ while (true) { if (queue.Count > 0) { Console.WriteLine("出队列-{0}", queue.Dequeue()); } }}运行结果
希望本文所述对大家的C#程序设计有所帮助。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
队列queue多应用在多线程应用中,多线程访问共享变量。对于多线程而言,访问共享变量时,队列queue是线程安全的。从queue队列的具体实现中,可以看出que
本文实例讲述了C#线程队列用法。分享给大家供大家参考。具体如下:usingSystem;usingSystem.Collections.Generic;usin
本文实例讲述了C#多线程处理多个队列数据的方法。分享给大家供大家参考。具体实现方法如下:usingSystem;usingSystem.Collections.
本文实例讲述了C#(asp.net)多线程用法。分享给大家供大家参考,具体如下:usingSystem;usingSystem.Collections.Gene
本文实例讲述了C#多线程之Thread中Thread.IsAlive属性用法。分享给大家供大家参考。具体如下:Thread.IsAlive属性,表示该线程当前是