#>【C#多线程】 动态创建多个线程后 需要关闭其中某个线程的解决实例。 using System; using System.Collections.Generic; using System.Text; using System.Threading; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { List listThread = new List(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