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/CheckServiceHelper.cs

36 lines
980 B
C#

using System;
using System.Collections.Generic;
1 year ago
using System.Configuration;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
namespace ServiceDeamon
{
public class CheckServiceHelper
{
private static ServiceController servCtl;
1 year ago
private static string ServName = ConfigurationManager.AppSettings["ServiceName"];
1 year ago
public static void CheckStatus()
{
1 year ago
if (servCtl == null || servCtl.ServiceName != ServName)
{
1 year ago
servCtl = new ServiceController(ServName);
}
1 year ago
Console.WriteLine($"服务 {ServName} 的当前状态:{servCtl.Status}");
if (servCtl != null && servCtl.Status == ServiceControllerStatus.Stopped)
{
1 year ago
Console.WriteLine($"服务已停止,自动启动:{ServName}");
servCtl.Start();
}
1 year ago
//Console.WriteLine("CheckStatus");
}
}
}