Windows 2003 服务和计时器问题导致 Tick 不被调用?
Win2k3 上的服务中的计时器存在一些问题... 基本上,创建一个服务,每 X 分钟/秒检查某个进程及其是否正在运行。 我认为完成此任务的最简单方法是通过计时器。
已成功安装该服务,并且似乎报告其启动/停止正常。 我已使用 Eventlog.WriteEntry 写入事件日志,并观察到它正在到达启动功能,但没有到达计时器滴答声。
EventLog.WriteEntry("SETTINGS SET");
// Set our timer's interval to the value set in the settings.xml file.
tmrCheck.Interval = Int32.Parse(_settingChkInterval) * 1000;
// Enable our timer and away we go, checking away!
tmrCheck.Enabled = true;
// Set our Tick event to our Tick void
tmrCheck.Tick += new EventHandler(tmrCheck_Tick_1);
Having a few problems with Timers within a service on Win2k3...
Basically, creating a service that every X minutes/seconds, checks for a certain process and whether it is running. I figured the easiest way to get this done was via a Timer.
Have managed to install the service fine, and it seems to be reporting that it is starting/stopping OK. I have written to the eventlog using Eventlog.WriteEntry, and have observed that it is reaching the startup function, but not the Timer Tick.
EventLog.WriteEntry("SETTINGS SET");
// Set our timer's interval to the value set in the settings.xml file.
tmrCheck.Interval = Int32.Parse(_settingChkInterval) * 1000;
// Enable our timer and away we go, checking away!
tmrCheck.Enabled = true;
// Set our Tick event to our Tick void
tmrCheck.Tick += new EventHandler(tmrCheck_Tick_1);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,您不能在服务中使用 Winform 计时器。
您需要使用 System.Timers.Timer 或 System.Threading.Timer。
Mmmm, you cant use a Winform timer in a service.
You need to use
System.Timers.Timer
orSystem.Threading.Timer
.