本文转自:http://blog.csdn.net/sharpnessdotnet/article/details/7637180
一定要使用System.Timers.Timer timer 而不是System.Windows.Forms.Timer,否则就悲剧了.
public partial class InvkGpsWinService : ServiceBase
{
System.Timers.Timer timer = new System.Timers.Timer();
public InvkGpsWinService()
{
InitializeComponent();
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
timer.Interval = ConfigHelper.ApplicationAutoRunTimeSpan;
}
void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
InvkGps.Library.BizLogic.BizLogicObject_TRUCK_DATA.Proxy.Run();
}
protected override void OnStart(string[] args)
{
// TODO: 在此处添加代码以启动服务。
timer.Enabled = true;
timer.Start();
}
protected override void OnStop()
{
// TODO: 在此处添加代码以执行停止服务所需的关闭操作。
timer.Enabled = false;
timer.Stop();
}
}
.net Windows Service安装包制作
http://blog.csdn.net/sqqyq/article/details/50475437