0 .查看当前的线程信息:Thread.CurrentThread.属性
![]()
1 private static Thread subthread ;
2 private static Thread subthread1;
3 static void Main(string[] args)
4 {
5 Thread.CurrentThread.Name = "Main线程";
6 Console.WriteLine(Thread.CurrentThread.Name);
7 //开启了一个新的线程
8 subthread = new Thread(new ThreadStart(GetShow)); //无参数的入口方法线程
9 subthread.Start(); //开启线程
10 subthread.Name = "无参数的入口方法线程";
11 //又开启了一个线程
12 subthread1 = new Thread(new ParameterizedThreadStart(GetShow)); //有参数的入口方法线程
13 subthread1.Start("实际参数");//开启线程传参
14 subthread1.Name = "有参数的入口方法线程";
15
16 Console.WriteLine("主线程结束");
17 }
18
19 static void GetShow()
20 {
21
22 Console.WriteLine(Thread.CurrentThread.Name);
23 Console.WriteLine("执行无参数的方法");
24 }
25
26 static void GetShow(object obj)
27 {
28 Console.WriteLine(Thread.CurrentThread.Name);
29 Console.WriteLine("执行有参数的方法,传参为:" + (string)obj);
30 }
31 }
View Code