Easy Company 的 .Net 开发博客
每一年,每一天,我都在进步!
2008年5月24日
ThreadPool 在.Net 2.0 SP1中的部分变化可能会让你的程序停止工作
最近
Michael C. Kennedy
在它的博客上写了一些关于.Net 2.0 SP1中ThreadPool的文章。
在
.NET 3.5 Brings Breaking Changes to ThreadPool
中他介绍了一个对他影响很大的变化,新的.NET 2.0 SP1(随.NET 3.5 发布)忽略了ThreadPool.SetMinThreads导致他的程序停止运行。如果你的应用需要立即使用大量的线程池线程时,你必须通过ThreadPool.SetMinThreads提高最小线程数量,否则ThreadPool会尽快在线程池中分配最少数量的线程,接着每秒钟创建最多2个线程,直到达到最大线程数量的方法启动线程,它可能需要几秒钟才能完成。在文章中Michael给出了100个线程的
测试示例
,并在
2008年2月26日
提供了
视频
和相应的新的
测试代码
。
另外Michael发现当太多线程等待其他任务结束时就会出现死锁,他通过向Vance Morrison(a .NET Runtime Performance Architect at Microsoft)确认那是一个Bug,他们将在.Net 2.0 SP2中修复。并且Vance给了Michael一个解决这个问题的
策略
,如下:
Take this "broken" code:
private
static
void
UseThreadPool(
int
count)
{
for
(
int
i
=
0
; i
<
count; i
++
)
{
ThreadPool.QueueUserWorkItem(
delegate
{ SlowMethod(); }
);
}
}
And add a strategic Thread.Sleep and it's fixed:
private
static
void
UseThreadPool(
int
count)
{
for
(
int
i
=
0
; i
<
count; i
++
)
{
ThreadPool.QueueUserWorkItem(
delegate
{ SlowMethod(); }
);
Thread.Sleep(
1
);
}
}
posted @ 2008-05-24 12:03 Easy Company 阅读(497) 评论(0)
编辑
导航
博客园
首页
新随笔
联系
订阅
管理
公告
本人在此发表的文章中可能存在错误,请各位指正,在此表示谢意。但不要因为看法不同而进行人身攻击,毕竟我没有从你那里得到什么,你也没有失去什么。
昵称:
Easy Company
园龄:
6年9个月
粉丝:
0
关注:
0
常用链接
我的随笔
我的评论
我的参与
最新评论
我的标签
我的标签
.net framework 3.5
(4)
2008
(3)
programming
(3)
performance
(2)
SQL Server
(2)
SQL Server FullText Search
(2)
.net framework 2.0
(2)
ajax
(2)
json
(2)
web
(2)
更多
随笔分类
Source code and Demo(15)
(rss)
Tip(3)
(rss)
开发日志(10)
(rss)
杂项(10)
(rss)
转载(11)
(rss)
随笔档案
2008年7月 (1)
2008年6月 (2)
2008年5月 (1)
2008年4月 (1)
2008年2月 (1)
2008年1月 (1)
2007年12月 (1)
2007年11月 (1)
2007年9月 (1)
2007年7月 (3)
2007年1月 (1)
2006年12月 (3)
2006年10月 (2)
2006年9月 (3)
2006年8月 (3)
2006年5月 (3)
2006年4月 (5)
2006年1月 (2)
2005年11月 (1)
2005年10月 (1)
2005年8月 (3)
2005年6月 (2)
2005年5月 (7)
文章分类
.net framework
(rss)
ASP.NET 服务器控件与组件开发
(rss)
.Net site
.NET 247
Check out the fastest growing and one of the most trafficked .NET developer resource sites for articles, a newsletter, programmers reference and more.
.netWire
.netWire is THE resource for Microsoft .NET related news.
AngryCoder
Check out this eZine, written completely using the Microsoft .NET Framework, where you can submit your own article and even download the site's source code for a minimal donation.
AspAdvice - Answers to Qustions
If you've got questions about ASP and ASP.NET, there are thousands of other developers waiting to answer them on AspAdvice.com.
ASPNETWorld.com
C# Corner
C# Corner is a free source site for C# and Microsoft .NET developers to meet and exchange ideas, code, and expertise through discussion forums or submissions.
C# Help
DevCity.NET
Join devCity.NET. Become a part of the fastest growing .NET community. Read expert articles on real life problems. Receive fast answers and be rewarded helping other members of the community.
DevX.com
Get the latest news and articles, sign up for newsletters or join a discussion group at this comprehensive site for .NET.
dotnetjunkies
DotNetJunkies.com is the premier online resource for ASP.NET tutorials, how-to's, events and jobs. And sample code is available in both Visual Basic .NET and C#.
GotDotNET
The Microsoft .NET Framework Community.
RegexAdvice Answers to Questions
If you have a question regarding regular expressions then you've come to the right place. RegexAdvice exists to provide Answers to your Regular Expression Questions.
Custom Control
Creating a Drill Down DataGrid with User Controls
Embed ASP.Net DataGrid Control Inside Another DataGrid Control
MetaBuilders Web Tools
Free controls (Open Source).
Nested Datagrids
Using Nested DataGrids in ASP.NET
MSDN
Code Samples on MSDN (commend)
A resource for developer samples and downloads.
MVP技术专栏——开发人员技术文章
SourceForge.Net
SourceForge.Net Home
The Code Project
Code Project Home
推荐
. 我在 MSN Spaces 上的博客
记录了我的点点滴滴,包括:想法、喜好等。
Firefox
搜索
我的技术博客
我的MSN博客
Web
最新评论
阅读排行榜
推荐排行榜