【问题标题】:Does ServiceController.WaitForStatus set the status or just wait?ServiceController.WaitForStatus 是设置状态还是等待?
【发布时间】: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


【解决方案1】:

没有。

From MSDN Documentations: 使用 WaitForStatus 暂停应用程序的处理,直到服务达到所需状态。

就是这样,它只会暂停调用线程并轮询状态 - 如文档中所述 - 每大约 250 毫秒,直到达到服务状态或超时。

【讨论】:

    猜你喜欢
    • 2012-03-18
    • 1970-01-01
    • 1970-01-01
    • 2010-10-30
    • 1970-01-01
    • 1970-01-01
    • 2012-06-19
    • 2023-04-09
    • 1970-01-01
    相关资源
    最近更新 更多