码迷,mamicode.com
首页 > 编程语言 > 详细

Thread 线程

时间:2016-05-17 06:20:34      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

线程 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

Thread 线程

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!