我现在有服务A, 服务B, 服务C我想用服务A定时去检测 服务B 和 服务C, 发现服务停止即重新开启服务。不知道有没有办法可以做到?
解决方案 »
- 有做过舆情分析系统的吗,我崩溃了~
- C#中 VS找不到microsoft agent control 2.0组件 怎么办?跟VS版本有关系么?
- C#数据库中遇到的问题。
- C# 读取word模板 处理动态级联 表格 问题?
- 关于动态调用DLL的问题~
- Input string was not in a correct format 出错.急.顶者有分!
- C#窗体如何在点击"删除"按钮、成功删除数据后,重新加载窗体?
- dataGridView连接SQL总显示登录失败
- 求教:用C#开发的WinForm应用程序是否能运行在Win98下
- 拖放一个文件到form得到他的path,如何做呢?
- C#数据库访问问题
- 标题过长问题
ServiceControllerStatus ls = sc.Status;
switch (sStatus)
{
case "Stopped":
if (ls == ServiceControllerStatus.Running || ls == ServiceControllerStatus.Paused)
{
sc.Stop();
}
break;
case "Paused": if (ls == ServiceControllerStatus.Running)
{
sc.Pause();
}
break;
case "Running": if (ls == ServiceControllerStatus.Stopped)
{
sc.Start();
}
else if (ls == ServiceControllerStatus.Paused)
{
sc.Continue();
}
break;
}
ServiceControllerStatus ls = sc.Status;
switch (sStatus)
{
case "Stopped":
if (ls == ServiceControllerStatus.Running || ls == ServiceControllerStatus.Paused)
{
sc.Stop();
}
break;
case "Paused": if (ls == ServiceControllerStatus.Running)
{
sc.Pause();
}
break;
case "Running": if (ls == ServiceControllerStatus.Stopped)
{
sc.Start();
}
else if (ls == ServiceControllerStatus.Paused)
{
sc.Continue();
}
break;
}
建议不要这样做。1、服务作为长时间运行的程序,本身应该是健壮的。用守护进程的方式来解决服务不稳定,只会带来新的问题。2、对于关键服务,Windows已经提供了恢复功能,允许在服务出错的情况下重启服务,甚至重启系统。