惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
V
Visual Studio Blog
P
Privacy International News Feed
月光博客
月光博客
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
Lohrmann on Cybersecurity
N
News and Events Feed by Topic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Apple Machine Learning Research
Apple Machine Learning Research
阮一峰的网络日志
阮一峰的网络日志
Webroot Blog
Webroot Blog
T
Threatpost
宝玉的分享
宝玉的分享
The Last Watchdog
The Last Watchdog
小众软件
小众软件
L
LINUX DO - 最新话题
C
Cisco Blogs
T
Troy Hunt's Blog
Schneier on Security
Schneier on Security
酷 壳 – CoolShell
酷 壳 – CoolShell
www.infosecurity-magazine.com
www.infosecurity-magazine.com
雷峰网
雷峰网
G
GRAHAM CLULEY
有赞技术团队
有赞技术团队
Know Your Adversary
Know Your Adversary
博客园 - 叶小钗
罗磊的独立博客
V
V2EX
博客园 - Franky
P
Proofpoint News Feed
SecWiki News
SecWiki News
腾讯CDC
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Jina AI
Jina AI
博客园 - 三生石上(FineUI控件)
S
Secure Thoughts
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Google DeepMind News
Google DeepMind News
Attack and Defense Labs
Attack and Defense Labs
人人都是产品经理
人人都是产品经理
The Cloudflare Blog
PCI Perspectives
PCI Perspectives
V2EX - 技术
V2EX - 技术
Google DeepMind News
Google DeepMind News
Last Week in AI
Last Week in AI
aimingoo的专栏
aimingoo的专栏
Cisco Talos Blog
Cisco Talos Blog
N
News and Events Feed by Topic
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
SegmentFault 最新的问题

博客园 - bartholomew

new作为修饰符时的使用,以及接口的显式实现 关键词:应用程序扩展,通配符应用程序映射 Silverlight 2 Beta 1在Firefox下显示时的一点小问题~ Visual Studio也有调试禁区?! 关于SQL Server 2005的版本号 使用动态SQL的一点小技巧 通过本地IIS SMTP服务器发送邮件时提示“邮箱不可用”的解决办法 使用System.Net.Mail.SmtpClient发送邮件时出现的乱码问题 写代码的心情 在XP上安装SQL Server 2000、Visual studio .net 2003、Visual studio 2005、SQL Server 2005…… XPS M1210到了~~~~ 在dell的网上订购了XPS M1210,耐心等待中…… 对PropertyGrid控件中PropertyValueChanged事件的探讨 关于邮件群发 关于Dotnet中的线程池 Dotnet中强行关闭多线程应用程序的所有线程 工作之余,自省~ 创建某控件的线程之外的其他线程试图调用该控件引发的问题 古怪的ConfigurationManager类
多线程编程中Join与WaitOne的区别
bartholomew · 2006-07-10 · via 博客园 - bartholomew

举例说明:
Join:在一个线程MainThread中开启一个新的线程NewThread,在完成初始化并启动NewThread的操作后,调用Join,则MainThread堵塞,直到NewThread执行完毕,MainThread才继续执行。

using System;
using System.Threading;

class IsThreadPool
{
    
static void Main()
    
{
        Console.WriteLine(
"MainThread start.");

        AutoResetEvent autoEvent 
= new AutoResetEvent(false);

        Thread NewThread 
=
            
new Thread(new ThreadStart(ThreadMethod));
        NewThread.Start();

        
// Wait for foreground thread to end.
        NewThread.Join();

        Console.WriteLine(
"MainThread end.");
    }


    
static void ThreadMethod()
    
{
        Console.WriteLine(
"haha,NewMethod");
    }

}


运行结果:
MainThread start.
haha,NewMethod
MainThread end.

WaitOne:在一个线程MainThread中开启一个新的线程NewThread,在完成初始化并启动NewThread的操作后,调用WaitOne,则MainThread堵塞,直到在NewThread中调用Set,MainThread才继续执行。

using System;
using System.Threading;

class WaitOne
{
    
static AutoResetEvent autoEvent = new AutoResetEvent(false);

    
static void Main()
    
{
        Console.WriteLine(
"MainThread start.");

        ThreadPool.QueueUserWorkItem(
            
new WaitCallback(WorkMethod), autoEvent);

        
// Wait for work method to signal.
        autoEvent.WaitOne();
        Console.WriteLine(
"MainThread continue.");

        Console.WriteLine(
"MainThread end.");
    }


    
static void WorkMethod(object stateInfo)
    
{
        Console.WriteLine(
"Work start.");

        
// Simulate time spent working.
        Thread.Sleep(new Random().Next(1002000));

        
// Signal that work is finished.
        Console.WriteLine("Work end.");
        ((AutoResetEvent)stateInfo).Set();
    }

}


运行结果:
MainThread start.
Work start.
Work end.
MainThread end.