参考文章:
http://www.cnblogs.com/xujie/p/5695673.html
上面的文章写的已经不错,有几点问题,进行了一下修改。
1.System.Timers.Timer控件从工具箱中拖入
在设计视图,工具箱,右键“选择项”,.NET Framework组件查找到System.Timers组件,然后勾选,确定。
再将刚才引入的Timer控件拖入调用。
2.Timer控件通过调用Start()和Stop()方法,而不是设置Enabled属性
在Service的OnStart方法里面调用Timer的Start方法;
在Service的OnStop方法里面调用Timer的Stop方法。
3.因为我们的Timer控件是拖入的,所以在设计页面双击即可编辑Elapsed时间的代码,不再需要进行绑定。
Service1.cs的完整代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using