// 判断条件
private bool stopFlag = false;
private DateTime runLastTime = DateTime.Now;
private Thread SynsThread = null;
private bool firstFlag = true;
protected override void OnStart(string[] args)
{
SynsThread = new Thread(方法); // 实例一个线程
SynsThread.Start(); // 启动线程
}
private void 方法()
{
while (stopFlag == false)
{
try
{
//你要执行的业务
FillDb.Fill();
}
catch
{
System.Diagnostics.EventLog.WriteEntry(ConfigurationManager.AppSettings["LogName"].ToString(), "程序执行出错!");
}
runLastTime = DateTime.Now;
firstFlag = false;
int WaitLength = int.Parse(ConfigurationManager.AppSettings["TimerLength"].ToString());
Thread.Sleep(WaitLength);
}
}
---------------------------
调错日志方法,就是简单的写入windows 日志
public void WriteLog(string logContent)
{
//可以加判断条件
System.Diagnostics.EventLog.WriteEntry("ServiceTest", logContent);
}