我有一个服务并制作了一个监控服务的小程序,如果服务出现故障就重新启动它......
我的问题是,如果我关闭监控程序,那么服务就会停止,我无法弄明白为什么......
我的程序如下所示
public static void Main(string[] args)
{
Task.Run(async () =>
{
var sc = new ServiceController("Explore");
var client = new HttpClient();
while (DateTime.Now.Hour >= 8 &&
DateTime.Now <= new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59))
{
sc.Refresh();
await Task.Delay(2000);
if (sc.Status != ServiceControllerStatus.Stopped && sc.Status != ServiceControllerStatus.Paused)
{
await Task.Delay(300000);
continue;
}
sc.Start();
sc.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, 10));
sc.Refresh();
// starts services that handle notifications
await client.GetAsync($"{host}/sqltorabbit/start");
await client.GetAsync($"{host}/notifications/indexer/Elastic/start");
await client.GetAsync($"{host}/notifications/push/Apple/start");
}
await Task.Delay(28800000);
}).Wait();
}
}
答案 0 :(得分:0)
错误发生在其他地方......
当代码启动服务时,它无法连接到Windows凭据上的数据库...但是如果设置为服务上的特定帐户登录,则它可以正常运行...