Thread 线程

线程 Join

一线程里面调用另一线程join方法时,表示将本线程阻塞直至另一线程终止时再执行

using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Runtime.Remoting.Messaging;

namespace ConsoleApplication
{
    public delegate string DeleMethod(string name);
    class Program
    {
        static void Main()
        {
            Thread t = new Thread(Run);

            t.Start();

            //Join相当于把Run方法内嵌如此
            //t.Join();

            //该死的t.Join(),害的我主线程必须在你执行完后才能执行。
            Console.WriteLine("我是主线程:" + Thread.CurrentThread.GetHashCode());
            Console.ReadLine();
        }

        static void Run()
        {
            //等待5s
            Thread.Sleep(5000);

            Console.WriteLine("我是线程:" + Thread.CurrentThread.GetHashCode());
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Runtime.Remoting.Messaging;

namespace ConsoleApplication
{
    public delegate string DeleMethod(string name);
    class Program
    {
        static void Main()
        {
            Thread t = new Thread(Run);

            t.Start();

            //Join相当于把Run方法内嵌如此
            t.Join();

            //该死的t.Join(),害的我主线程必须在你执行完后才能执行。
            Console.WriteLine("我是主线程:" + Thread.CurrentThread.GetHashCode());
            Console.ReadLine();
        }

        static void Run()
        {
            //等待5s
            Thread.Sleep(5000);

            Console.WriteLine("我是线程:" + Thread.CurrentThread.GetHashCode());
        }
    }
}

http://www.cnblogs.com/huangxincheng/archive/2012/03/14/2395279.html

原文地址:https://www.cnblogs.com/hongdada/p/5500134.html