C#队列Queue多线程用法实例
作者:永远爱好写程序 时间:2023-03-09 20:12:09
本文实例讲述了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#程序设计有所帮助。
标签:C#,队列,Queue,多线程
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
C# 类的声明详解
2022-10-15 14:08:38
SpringSecurity权限控制实现原理解析
2022-04-05 14:46:27
![](https://img.aspxhome.com/file/2023/0/102630_0s.png)
Unity3D实现飞机大战游戏(2)
2021-11-16 10:41:38
![](https://img.aspxhome.com/file/2023/7/113817_0s.jpg)
win10下配置java环境变量的方法
2022-08-23 17:10:11
![](https://img.aspxhome.com/file/2023/4/71134_0s.png)
Java中Map遍历的九种方式汇总
2023-05-02 21:57:27
![](https://img.aspxhome.com/file/2023/6/82376_0s.jpg)
Android 开发程序锁应用简单实例
2021-10-07 07:41:34
![](https://img.aspxhome.com/file/2023/4/139224_0s.png)
Java web spring异步方法实现步骤解析
2023-12-19 03:14:58
微服务间调用Retrofit在Spring Cloud Alibaba中的使用
2022-09-29 23:13:42
![](https://img.aspxhome.com/file/2023/0/75660_0s.png)
IDEA 使用mybatis插件Free Mybatis plugin的步骤(推荐)
2022-12-05 02:01:03
![](https://img.aspxhome.com/file/2023/8/72328_0s.jpg)
Java解决计算相邻两个数的最大差值的问题
2022-03-29 05:47:20
![](https://img.aspxhome.com/file/2023/7/94307_0s.png)
浅谈java异常链与异常丢失
2023-10-24 21:53:38
SpringBoot 集成 Druid过程解析
2023-02-25 12:07:59
![](https://img.aspxhome.com/file/2023/5/71655_0s.png)
Qt GUI图形图像开发之Qt表格控件QTableView简单使用方法及QTableView与QTableWidget区别
2022-02-23 05:02:59
![](https://img.aspxhome.com/file/2023/4/117774_0s.jpg)
详解spring boot 使用application.properties 进行外部配置
2023-02-13 02:09:11
![](https://img.aspxhome.com/file/2023/7/125227_0s.png)
Android自定义控件绘制基本图形基础入门
2023-06-23 07:19:04
Android自定义DigitalClock控件实现商品倒计时
2023-07-17 20:13:28
![](https://img.aspxhome.com/file/2023/8/138988_0s.jpg)
C#利用iTextSharp组件给PDF文档添加图片/文字水印
2021-11-03 20:18:31
Java应用层协议WebSocket实现消息推送
2022-05-09 07:26:29
![](https://img.aspxhome.com/file/2023/0/94370_0s.png)
springboot嵌套子类使用方式—前端与后台开发的注意事项
2023-09-16 12:37:22
Android GestureDetector手势滑动使用实例讲解
2022-01-18 01:34:12
![](https://img.aspxhome.com/file/2023/4/88704_0s.jpg)