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

推荐订阅源

D
DataBreaches.Net
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
B
Blog
博客园 - Franky
I
InfoQ
A
About on SuperTechFans
博客园_首页
L
LangChain Blog
量子位
腾讯CDC
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
美团技术团队
V
V2EX
Apple Machine Learning Research
Apple Machine Learning Research
雷峰网
雷峰网
MongoDB | Blog
MongoDB | Blog
Microsoft Azure Blog
Microsoft Azure Blog
月光博客
月光博客
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
G
Google Developers Blog
Last Week in AI
Last Week in AI

博客园 - 浅水滩

VSTS FAQ 配置Team Build的每日构建 WORD 2007向博客园发布BLOG 一不小心删除了“Team Foundation Licensed Users”组中的用户后的恢复 我猜到了开始,却没有猜到结局 --深叹2006足球世界杯决赛 有感于“快乐地消灭软件工业” 蜗牛的家 Google的秘密 -- 《Google成功的七堂课》读后感 NHibernate的关键点精要 NHibernate 0.9 发布了 驳:光荣与失落 开发工程师人生之路 Subversion Server For Windows安装指南 NHIBERNATE的几个问题 JUNIT IN Action (1) 将企业应用进行到底 .NET企业应用架构所要解决的若干问题 MAVERICK.NET初窥(原创) 在ASP.NET中解析类似http://abc.com/product?x=1111完全解决方案 Shadowfax 架构(自己翻译)
System.Timers.Timer在Windows Services程序中工作不正常的问...
浅水滩 · 2005-01-22 · via 博客园 - 浅水滩

问题:

在windows service程序中,定时器在运行一段时间后不工作

分析:

在查阅了大量的资料后,我们发现导致这个错误的原因是因为.NET FrameworkSystem.Timers.Timerbug导致的。以下是该BUG的简单信息:

BUG: The Elapsed event of the System.Timers.Timer class is not raised in a Windows service

Article ID

:

KB 842793

Last Review

:

July 27, 2004

Revision

:

1.0

SYMPTOMS

You can use the Microsoft .NET Framework to create a new Microsoft Windows service that contains a System.Timers.Timer object. When you run this new Windows service, the Elapsed event of the System.Timers.Timer class may not be raised.

CAUSE

Note In this section, the System.Timers.Timer object is referred to as the Timer object.

In the event handler for the Elapsed event of the Timer object, if you call the Stop method of the Timer object, the reference to the Timer object is lost. The garbage collector then reclaims the memory that is associated with the Timer object. Later, even if you call the Start method of the Timer object to raise the Elapsed event, the call does not work. The Elapsed event is not raised.

WORKAROUND

To work around this problem, use a System.Threading.Timer object instead of the System.Timers.Timer object.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

详见以下链接内容,http://support.microsoft.com/default.aspx?scid=kb;EN-US;842793

解决方案:

按照KB 842793的建议,用System.Threading.Timer替换System.Timers.Timer