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.
BookingHeChuan/ServiceDeamon/DeamonService.cs

46 lines
1.1 KiB
C#

1 year ago
using NLog;
using System;
1 year ago
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"]);
1 year ago
private readonly Logger log = LogManager.GetCurrentClassLogger();
1 year ago
public bool Start(HostControl hostControl)
{
1 year ago
log.Info("服务启动");
1 year ago
timer = new Timer(new TimerCallback(CheckSta));
timer.Change(CheckInteval, Timeout.Infinite);
return true;
}
public bool Stop(HostControl hostControl)
{
1 year ago
log.Info("服务停止");
1 year ago
timer.Change(-1, 0);
return true;
}
private static void CheckSta(object sta)
{
CheckServiceHelper.CheckStatus();
timer.Change(CheckInteval, Timeout.Infinite);
}
}
}