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(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 2015-08-29 19:52  qqhfeng16  阅读(638)  评论(0编辑  收藏  举报