【问题标题】:C# service not starting on first rebootC# 服务未在第一次重新启动时启动
【发布时间】:2018-05-19 17:36:50
【问题描述】:

我有一个用 C# 4.61 编写的 Windows 服务。在未修补的 Windows 2008R2、Windows 2012R2 或 Windows 2016 服务器上,它在安装后第一次重新启动时拒绝自动启动。

我什至将它设置为自动(延迟启动),它仍然给出错误:

Entry 1

A timeout was reached (30000 milliseconds) while waiting for (servicename) service to connect.

Entry 2

The (servicename) service failed to start due to the following error: The service did not respond to the start or control request in a timely fashion.

从那时起任何重启都没有问题。

我知道正确的做法是修补系统,但是我希望能够确定修复此问题的修补程序/更新。

在我进行的所有搜索中,大多数人建议延长全局服务超时以纠正此问题,而我无法接受在某人的生产机器上更改全局设置。

我知道问题不在于我的服务需要多长时间才能启动,因为手动启动它只需要几秒钟。

【问题讨论】:

  • 我在这里建议的主要事情是:在开始时做的更少。将大多数事情推迟到一个单独的线程 - 也许看看您在启动循环中唯一需要做的事情是检查配置以查看您应该能够启动。
  • 我什至在一个线程中启动了整个服务进程,这应该让它几乎立即启动。但是我遇到了同样的问题。

标签: c# .net windows service server


【解决方案1】:

你应该试试这个:

System.Threading.Tasks.Task.Run(() =>
{
    this.YourFunction();
});

private void YourFunction()
{
    // Your code
}

【讨论】:

  • 这是我最初尝试的解决方案之一,没有区别。
猜你喜欢
  • 1970-01-01
  • 2019-08-23
  • 1970-01-01
  • 1970-01-01
  • 2014-12-08
  • 1970-01-01
  • 2011-04-21
  • 2019-03-03
相关资源
最近更新 更多