博客园站长
这是人类成长进步中记录的每一时刻

转自:http://blog.csdn.net/lulu_jiang/article/details/6584251

线程Join()方法:让一个线程等待另一线程终结后再继续运行。

 

private static void Method()
{
    Thread.Sleep(5000);
    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();
}

 

posted on 2014-08-06 16:48  dm3344  阅读(155)  评论(0编辑  收藏  举报