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