public override void UpdateStatus()
 {
     if (!string.IsNullOrWhiteSpace(selfFullExcutableFilePath))
     {
         if (Srvany.IsServiceRunning(WATCHDOG_SERVICE_NAME))
         {
             if (!Srvany.IsProcessExists(selfFullExcutableFilePath))
             {
                 Srvany.StopService(WATCHDOG_SERVICE_NAME);
             }
         }
     }
     base.UpdateStatus();
 }
Example #2
0
        static void Main(string[] args)
        {
            var config = ConfigManager.Instance.Value.Config;

            IEnumerable <ServiceWatchInfo> serviceInfos = config?.ServiceList;

            if (serviceInfos != null)
            {
                while (true)
                {
                    try
                    {
                        foreach (var srvInfo in serviceInfos)
                        {
                            if (!IsServiceInfoValid(srvInfo))
                            {
                                continue;
                            }

                            //先负责纠正服务状态
                            //因为有可能服务显示“正在运行”但是进程列表里没有那个进程
                            if (IsServiceRunning(srvInfo.ServiceName))
                            {
                                if (!Srvany.IsProcessExists(srvInfo.FullExePath))
                                {
                                    Srvany.StopService(srvInfo.ServiceName);
                                }
                            }
                            else
                            {
                                //如果需要守护该服务,则发现服务没在运行后,把该服务启动
                                Srvany.RunService(srvInfo.ServiceName);
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                    Thread.Sleep(2000);
                }
            }
        }