“错误1053服务未响应".使用TopShelf创建Windows服务时出现错误 [英] "Error 1053 The Service did not respond" error when using TopShelf to create a Windows Service

查看:75
本文介绍了“错误1053服务未响应".使用TopShelf创建Windows服务时出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 TopShelf 库创建的Windows服务.尝试启动服务时,它给我一个错误:

I have a Windows Service created using the TopShelf library. When attempting to start the service, it gives me an error:

Windows无法在本地计算机上启动HPS.MyService.Service服务

Windows could not start the HPS.MyService.Service service on Local Computer

错误1053:服务未及时响应控制请求的开始.

Error 1053: The service did not respond to the start of control request in a timely fashion.

此错误在启动后立即发生,没有30秒的延迟.

This error happens immediately on startup, there is no 30 second delay.

我的服务的TopShelf代码如下:

The TopShelf code for my service looks like this:

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?

推荐答案

此服务的安装名称为"HPS.MyService.Service".如错误消息所示,但是C#代码尝试将其显式设置为"HPS.MyService".名称之间的这种不匹配是错误的根源.您可以将服务更改为"HPS.MyService".安装时,或将服务名称行更改为

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". 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

x.SetServiceName("HPS.MyService.Service");

或者:完全删除对x.SetServiceName的调用,因为这限制了您只能使用服务的特定名称,并且无论如何安装它都可以控制该服务的名称.

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.

这篇关于“错误1053服务未响应".使用TopShelf创建Windows服务时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆