You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.1 KiB
C#
46 lines
1.1 KiB
C#
using NLog;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Topshelf;
|
|
|
|
namespace ServiceDeamon
|
|
{
|
|
public class DeamonService : ServiceControl
|
|
{
|
|
private static Timer timer;
|
|
private static int CheckInteval = Convert.ToInt32(ConfigurationManager.AppSettings["CheckInteval"]);
|
|
|
|
private readonly Logger log = LogManager.GetCurrentClassLogger();
|
|
|
|
public bool Start(HostControl hostControl)
|
|
{
|
|
log.Info("服务启动");
|
|
timer = new Timer(new TimerCallback(CheckSta));
|
|
timer.Change(CheckInteval, Timeout.Infinite);
|
|
|
|
return true;
|
|
}
|
|
|
|
public bool Stop(HostControl hostControl)
|
|
{
|
|
log.Info("服务停止");
|
|
timer.Change(-1, 0);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
private static void CheckSta(object sta)
|
|
{
|
|
CheckServiceHelper.CheckStatus();
|
|
|
|
timer.Change(CheckInteval, Timeout.Infinite);
|
|
}
|
|
}
|
|
}
|