1、Timer控件失效的解决
在Windows 服务不引发计时器事件
原因:
我认为windows服务里不能使用System.Windows.Forms的Timer控件,Windows.Forms 计时器组件用于 Windows.Forms 环境。 WindowsForms 计时器组件不用于服务器环境,所以要使用System.Timer下的控件。
解决方案
这个可以通过修改控件的类型,把所有使用服务器计时器从命名空间 System.Timers 代替 System.Windows.Forms 计时器。注意System.Timers的事件是Elapsed事件
如:
Service1.Designer.cs
1
namespace MyNewService
2
}
Service1.cs:2
1
using System;
2
using System.Collections.Generic;
3
using System.ComponentModel;
4
using System.Data;
5
using System.Diagnostics;
6
using System.ServiceProcess;
7
using System.Text;
8
9
namespace MyNewService
10
2
3
4
5
6
7
8
9
10