thread.Join(); 让主线程等待自己完成

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading; namespace ConsoleApplication1
{
class Program
{
private static void Method()
{
Thread.Sleep();
Console.WriteLine("当前线程:" + Thread.CurrentThread.Name);
} static void Main(string[] args)
{
Thread.CurrentThread.Name = "MainThread"; Thread thread = new Thread(Method);
thread.Name = "Thread";
thread.Start();
//会阻止主线程,直到thread线程终结(线程方法返回或线程遇到异常)
//输出:当前线程:Thread
// 主线程:MainThread
//可以注销此句对比输出结果
thread.Join(); Console.WriteLine("主线程:" + Thread.CurrentThread.Name); Console.Read();
}
}
}
上一篇:Log4NET的日志框架的使用


下一篇:关于System.getProperty("java.io.tmpdir");的输出,及System.getProperty();参数