• 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

  • 相关阅读:
    Sum of a Function(区间筛)
    (01背包)输出方案数
    删边求概率
    完全背包输出方案数(dp)
    二分
    Just Arrange the Icons(模拟)
    Balls of Buma(回文串)
    dp思想
    刷题-力扣-190. 颠倒二进制位
    刷题-力扣-173. 二叉搜索树迭代器
  • 原文地址:https://www.cnblogs.com/hongdada/p/5500134.html
Copyright © 2020-2023  润新知