I have developed a windows service using Topshelf. it works fine locally. When i deployed to test and try to start the service, it is giving me the following error:
Error 1053: The service did not respond to the start or control request in a timely fashion.
The test server is running on Windows server 2012.
This is my service start and stop methods:
public void Start()
{
_logProvider.Info("Service started.");
StartScheduledJobs();
}
public void Stop()
{
_scheduler.Shutdown(true);
_logProvider.Info("Service stopped.");
}
private void StartScheduledJobs()
{
try
{
_scheduler.Start();
ScheduleDeleteJob();
}
catch (Exception ex)
{
_logProvider.Error("", ex);
}
}
Can anyone help me what could be the reason with the solution please?
Thanks
The problem is that you are starting the service's work in the Start()
method.
This works fine during development, but when you install a service, the Service Control manager calls Start and waits 30 seconds for it to return - if it does, then the service is considered to have installed successfully.
Because you start your scheduled jobs, though, in the Start method, it doesn't return within that time, and you get this error.
The resolution is to start the work indirectly in Start and then return - start a dedicated thread to do it, or use a timer, there are lots of options.
Here this issue has been resolved: https://github.com/Topshelf/Topshelf/issues/183
In a nutshell: your Start() method should return true when service starts.
After trying every other solution without success I found a solution that solved my problem with the same error message.
public static int Main(string[] args)
{
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
//...
}
Based on https://github.com/Topshelf/Topshelf/issues/473
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With