码迷,mamicode.com
首页 > Windows程序 > 详细

windows服务定时任务

时间:2015-05-19 16:26:25      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:

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);
}
}
}

windows服务定时任务

标签:

原文地址:http://www.cnblogs.com/xiguanjiandan/p/4514745.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!