zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    IOS 获取时间的问题
    JQ 点赞
    截取字符串第一个空格前的字符
    JQ 的一些方法
    匿名函数var a =function(){}和function a(){}的区别
    完美支持中文编程的 Emacs 配置文件 .emacs
    linux find 命令忽略某个或多个子目录的方法
    Linux下如何用date设置时间
    nagios的监控代码!
    shell脚本监控apache进程数和oracle连接数
  • 原文地址:https://www.cnblogs.com/hongdada/p/5500134.html
Copyright © 2011-2022 走看看