partial class MainService : ServiceBase
{
public MainService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
// TODO: 在此处添加代码以启动服务。
//写日志启动服务
this.timer1.Enabled = true;
}
protected override void OnStop()
{
// TODO: 在此处添加代码以执行停止服务所需的关闭操作。
this.timer1.Enabled = false;
}
private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
this.timer1.Enabled = false;
this.timer1.Interval = Convert.ToDouble(ConfigurationSettings.AppSettings["CheckTime"].ToString());
WarningClass wClass = new WarningClass();
wClass.Sync();
}
catch (Exception ex)
{
//写日志
}
finally
{
this.timer1.Enabled = true;
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Configuration;
namespace SyncSmsService
{
partial class MainService : ServiceBase
{
public MainService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
// TODO: 在此处添加代码以启动服务。
//写日志启动服务
this.timer1.Enabled = true;
}
protected override void OnStop()
{
// TODO: 在此处添加代码以执行停止服务所需的关闭操作。
this.timer1.Enabled = false;
}
private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
this.timer1.Enabled = false;
this.timer1.Interval = Convert.ToDouble(ConfigurationSettings.AppSettings["CheckTime"].ToString());
SmsDAL dal = new SmsDAL();
dal.SendSms();
}
catch (Exception ex)
{
//写日志
}
finally
{
this.timer1.Enabled = true;
}
}
}
}