C#服务无法在首次重启时启动

时间:2017-12-05 23:03:24

标签: c# .net windows service server

我有一个用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.

从那时起重新启动它就没有问题。

我知道正确的方法是修补系统,但是我希望能够识别出哪个修补程序/更新可以解决这个问题。

在我完成的所有搜索过程中,大多数人都建议延长全局服务超时以纠正此问题,而且我无法接受更改某些生产计算机上的全局设置。

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

1 个答案:

答案 0 :(得分:0)

你应该试试这个:

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

private void YourFunction()
{
    // Your code
}
相关问题