Join,单词本事就是连接的意思。
先贴出几段代码猜猜结果。
 <1>       public static int Main()
        {         
            Alpha oAlpha = new Alpha();

            Thread Thread1 = new Thread(delegate() {
                Console.WriteLine("A");              
            });
            Thread1.Start();
            Console.WriteLine("a");
            return 0;
        }
结果是先打印 A 还先打印 a ?
  <2>     public static int Main()
        {         
            Alpha oAlpha = new Alpha();

            Thread Thread1 = new Thread(delegate() {
                Console.WriteLine("A");              
            });
            Thread1.Start();
            Thread1.Join();//注意这里
            Console.WriteLine("a");
            return 0;
        }
结果是先打印 A 还先打印 a ?
------------------------------------------------------
<3>
   static void Main(string[] args)
        {
            //线程A
            Thread ThreadA = new Thread(delegate()
            {
                for (int i = 0; i < 10; i++)
                {
                    Console.WriteLine("A : " );
                    if (i == 9)
                    {
                        break;
                    }
                    Thread.Sleep(1000);
                }

            });
            //线程B
            Thread ThreadB = new Thread(delegate()
            {
                for (int i = 0; i < 5; i++)
                {
                    Console.WriteLine("B : ");
                    if (i == 4)
                    {
                        break;
                    }
                    Thread.Sleep(1000);
                }
             ThreadA.Join();//在这里插入线程A
                for (int i = 0; i < 5; i++)
                {
                    Console.WriteLine("C : " );
                    if (i == 4)
                    {
                        break;
                    }
                    Thread.Sleep(1000);
                }
            });
            ThreadA.Start();
            ThreadB.Start();
        }
<4>
   public static int Main()
        {
            Thread.CurrentThread.Join();
            Console.WriteLine("O(∩_∩)O哈哈");
            return 0;
        }
----------------------------------------------------
运行结果:
1 A 和 a不分先后,Thread1线程很简单启动耗时非常小,Thread1线程和主线程几乎是同步的,所以打印A a不分前后根据CPU当时运行环境决定。
         2 先打印A 再打印 a ,因为Thread1执行了Join(),相当于在主线程中添加了Thread1线程,就是说只有当Thread1执行结束之后主线程才能继续执行。换句话说在主线程中嵌了一段代码,只有这段代码执行结束(这里不要以为调用了Join()线程Thread1会从头开始执行,不明白这句话可以运行下第3端程序),主线程才可以继续执行后面的代码。
         3 前5秒 A B交替出现,然后A出现5次,C出现5次。
如果注释掉ThreadA.Join(),那么结果是前5秒AB 交替出现 后5秒AC交替出现。
这里我就不再罗嗦了。还是那样线程B中join了线程A只有A执行结束,才可以继续执行线程B中剩下的代码。
join其实就是使异步执行线程转为同步执行。
         4 主线程被终止