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

推荐订阅源

博客园 - 【当耐特】
Help Net Security
Help Net Security
P
Proofpoint News Feed
J
Java Code Geeks
爱范儿
爱范儿
Last Week in AI
Last Week in AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
F
Full Disclosure
Google DeepMind News
Google DeepMind News
H
Help Net Security
G
Google Developers Blog
Jina AI
Jina AI
Vercel News
Vercel News
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
L
Lohrmann on Cybersecurity
S
Schneier on Security
Microsoft Azure Blog
Microsoft Azure Blog
IT之家
IT之家
Security Archives - TechRepublic
Security Archives - TechRepublic
阮一峰的网络日志
阮一峰的网络日志
N
News and Events Feed by Topic
GbyAI
GbyAI
B
Blog
O
OpenAI News
博客园_首页
Cisco Talos Blog
Cisco Talos Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Hacker News: Ask HN
Hacker News: Ask HN
TaoSecurity Blog
TaoSecurity Blog
腾讯CDC
MongoDB | Blog
MongoDB | Blog
M
MIT News - Artificial intelligence
C
Cybersecurity and Infrastructure Security Agency CISA
Cyberwarzone
Cyberwarzone
Webroot Blog
Webroot Blog
Simon Willison's Weblog
Simon Willison's Weblog
Y
Y Combinator Blog
C
Cisco Blogs
A
Arctic Wolf
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
The Exploit Database - CXSecurity.com
Security Latest
Security Latest
AI
AI
W
WeLiveSecurity
aimingoo的专栏
aimingoo的专栏
The Register - Security
The Register - Security
Project Zero
Project Zero
H
Hackread – Cybersecurity News, Data Breaches, AI and More
N
Netflix TechBlog - Medium
Blog — PlanetScale
Blog — PlanetScale

博客园 - 飞越梦想

[转]ASP.NET 数据绑定常用代码 简单调用VS自带的数据源选择对话框实现数据库连接字符串配置 Lucene.Net 系列 [转]lucene学习笔记三 各种query [转]JS获取屏幕,浏览器,网页高度宽度 第一次离线写Blog,先上个图先 模态窗口中提交表单时总在新窗口打开的解决办法 获取滚动条高度 JS获取select-option text extjs form中隐藏textfield的方法 JavaScript 常用函数 SQL日期格式化应用大全 [导入]Enterprise Library 3.1 帮助文档中文翻译 [导入]7.1.1 [Enterprise Library]缓存应用程序块场景和目标 [导入]第 7 章 缓存应用程序块 [导入]4.3 [Enterprise Library]定制中等信任策略 [导入]4.2 [Enterprise Library]版本 [导入]4.1 为部署准备 Enterprise Library [导入]第 4 章 部署 Enterprise Library
[原创]如何判断线程池中所有的线程是否已经完成
飞越梦想 · 2009-09-18 · via 博客园 - 飞越梦想

其实很简单用ThreadPool.RegisterWaitForSingleObject方法注册一个定时检查线程池的方法,在检查线程的方法内调用ThreadPool.GetAvailableThreads与ThreadPool.GetMaxThreads并比较两个方法返回的值是不是相等,相等表示线池内所有的线程已经完成.

//每秒检次一次线程池的状态
RegisteredWaitHandle rhw = ThreadPool.RegisterWaitForSingleObject(AutoResetEvent(false), this.CheckThreadPool, null1000false);//检查线程池的方法
       private void CheckThreadPool(object state, bool timeout)
        {
            
int workerThreads = 0;
            
int maxWordThreads = 0;
            
//int 
            int compleThreads = 0;
            ThreadPool.GetAvailableThreads(
out workerThreads, out compleThreads);
            ThreadPool.GetMaxThreads(
out maxWordThreads, out compleThreads);
            
//当可用的线数与池程池最大的线程相等时表示线程池中所有的线程已经完成
            if (workerThreads == maxWordThreads)
            {
                
//当执行此方法后CheckThreadPool将不再执行
                rhw.Unregister(null);
      
//此处加入所有线程完成后的处理代码               
            }
            

        }