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

推荐订阅源

H
Help Net Security
爱范儿
爱范儿
V
Visual Studio Blog
Last Week in AI
Last Week in AI
阮一峰的网络日志
阮一峰的网络日志
雷峰网
雷峰网
Hugging Face - Blog
Hugging Face - Blog
博客园 - 【当耐特】
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 三生石上(FineUI控件)
博客园 - Franky
博客园 - 叶小钗
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
大猫的无限游戏
大猫的无限游戏
人人都是产品经理
人人都是产品经理
M
MIT News - Artificial intelligence
罗磊的独立博客
L
LangChain Blog
Jina AI
Jina AI
IT之家
IT之家
J
Java Code Geeks
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页

博客园 - 浅水滩

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