【发布时间】:2016-10-06 10:52:13
【问题描述】:
我第一次使用ServiceController.WaitForStatus 来限制浪费在尝试启动无法启动的服务上的时间。我的假设是这样使用它:
var sc = new ServiceController(_monitoredService);
var seconds = _startWaitTimeout / 1000;
sc.Start();
sc.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, 0, seconds));
if (sc.Status != ServiceControllerStatus.Running)
{
_logger.Warn($"'{_monitoredService}' did not start within {seconds} seconds.");
}
然后我肩膀上的一个小恶魔建议WaitForStatus 可能会在等待之前尝试设置状态。是吗?
【问题讨论】:
-
No。来自 Docs:使用 WaitForStatus 暂停应用程序的处理,直到服务达到所需状态。 仅此而已。
-
@makadev 那就回答吧,我会接受的。
-
投反对票是怎么回事,小家伙?我不知道 required status 是指调用
WaitForStatus中的那个,还是之前的状态设置调用中的那个。
标签: c# .net windows-services .net-4.6 servicecontroller