public partial class TimerByThread : ServiceBase
{
public TimerByThread()
{
InitializeComponent();
}
ThreadStart ts = new ThreadStart(WriteLog.WriteLogToD);
Thread thread;
protected override void OnStart(string[] args)
{
try
{
thread = new Thread(ts);
if (true)
{
if (thread.ThreadState != System.Threading.ThreadState.Running)
{
thread.Start();
}
WriteLog.WriteLogToD();
Thread.Sleep(1000*60);
}
}
catch (Exception e)
{
WriteLog.WriteLogToD("开始时出错:" + e.Message);
}
}
protected override void OnStop()
{
try
{
if (thread.ThreadState != System.Threading.ThreadState.Stopped)
{
thread.Abort();
}
}
catch (Exception e)
{
WriteLog.WriteLogToD("停止时出错:"+e.Message);
}
}
}