0
votes

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

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

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

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

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?

1

1 Answers

1
votes

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");

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.