#>【C#多线程】 动态创建多个线程后 需要关闭其中某个线程的解决实例。 using System; using System.Collections.Generic; using System.Text; using System.Threading; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { List<Thread> listThread = new List<Thread>(5); Thread thread = null; for (int i = 0; i < 5; i++) { thread = new Thread(ThreadMethod); thread.Name = "Thread" + i; Console.WriteLine("创建 Thread" + i); listThread.Add(thread); thread.Start(i); Thread.Sleep(i * 100); } //关闭指定线程 foreach (Thread tempThread in listThread) { if (tempThread.Name == "Thread3") { Console.WriteLine(tempThread.Name + " 线程已关闭"); tempThread.Abort(); } } Console.ReadLine(); } private static void ThreadMethod(object t) { Thread.Sleep(1500); Console.WriteLine(String.Format("我是 Thread{0}", t)); } } } for (int i = 0; i < 5; i++) { Thread thread = new Thread(test) ; thread.Start(); } 如何关闭其中的一个线程呢? 请下载解决方案。 呵呵,这个实例10分值的买, 觉得好的话就评个分吧,评分后会返回你11分 (一定要评分,光评论是不返分的)
- 1
- 粉丝: 127
- 资源: 139
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于QT+C++做界面+使用esunny外盘api实现的一个快速行情、交易系统+源码+开发文档说明(毕业设计&课设&项目开发)
- 三菱PLC例程源码单钮起停控制程序三例
- oracle相关数据库的知识,包括建表语句,索引视图,触发器存储过程等
- MATLAB人脸识别+可调摄像头,库外判别预警,GUI界面.zip
- Oracle数据库备份与恢复.pdf
- 302P-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- 基于servlet的游戏商城(采用RESTful架构风格).zip
- 三菱PLC例程源码单按钮正反停
- C# 飞机大战项目, 获取道具,双排子弹 散弹的实现
- 三菱PLC例程源码单按钮五台电机启停控制SFC程序
- 1
- 2
- 3
前往页