[英]"Error 1053 The Service did not respond" error when using TopShelf to create a Windows Service
I have a Windows Service created using the TopShelf library.我有一个使用TopShelf库创建的 Windows 服务。 When attempting to start the service, it gives me an error:
尝试启动服务时,它给了我一个错误:
Windows could not start the HPS.MyService.Service service on Local Computer
Windows 无法在本地计算机上启动 HPS.MyService.Service 服务
Error 1053: The service did not respond to the start of control request in a timely fashion.
错误 1053:服务没有及时响应启动控制请求。
This error happens immediately on startup, there is no 30 second delay.此错误在启动时立即发生,没有 30 秒延迟。
The TopShelf code for my service looks like this:我的服务的 TopShelf 代码如下所示:
public static void Main()
{
HostFactory.Run(x =>
{
x.Service<TopshelfHangfireService>();
x.EnableServiceRecovery(r => r.RestartService(TimeSpan.FromSeconds(30)));
x.SetServiceName("HPS.MyService");
x.StartAutomaticallyDelayed();
});
}
I've validated that I can run this service directly from a console window by invoking the executable using the same account that the service is supposed to run as.我已经验证我可以直接从控制台窗口运行此服务,方法是使用服务应该运行的相同帐户调用可执行文件。
Why am I getting this error - how can I get my service to successfully start?为什么我会收到此错误 - 如何让我的服务成功启动?
This service was installed with a service name of "HPS.MyService.Service" as the error message indicates, but the C# code tries to explicitly set it to "HPS.MyService".如错误消息所示,此服务是使用“HPS.MyService.Service”服务名称安装的,但 C# 代码尝试将其显式设置为“HPS.MyService”。 This mismatch between names is the source of the error.
名称之间的这种不匹配是错误的根源。 You can change the service to be called "HPS.MyService" when installing it, or change the service name line to
您可以在安装时将服务更改为“HPS.MyService”,或者将服务名称行更改为
x.SetServiceName("HPS.MyService.Service");
Or: entirely remove the call to x.SetServiceName, since that limits you to using a particular name for the service, and you're able to control the service name when installing it anyways.或者:完全删除对 x.SetServiceName 的调用,因为这限制了您对服务使用特定名称,并且无论如何您都可以在安装时控制服务名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.