We are using Topshelf to host a service. Before starting the service, we are making database call to load lot of data. Because of this, while starting the service, we are getting following error:
Start Service failed with return code '[7] ServiceRequestTimeout
We are using following code to start the service:
HostFactory.Run(x =>
{
x.Service<AppService>(s =>
{
s.ConstructUsing(name => new AppService(s_resolver, baseAddress, resolver));
s.WhenStarted(svc => svc.Start());
s.WhenStopped(svc => svc.Stop());
s.WhenShutdown(svc => svc.Shutdown());
});
x.EnableShutdown();
x.RunAsLocalService();
x.StartAutomatically();
x.SetDisplayName("Application Host");
x.SetDescription("Application Host");
});
If I try to launch the service using Visual Studio, service runs fine. But when the service is hosted through Topshelf, I am getting time out error.
I have also tried using hostControl.RequestAdditionalTime(TimeSpan.FromSeconds(300))
but even after adding additional timeout period, I am not able to resolve the issue. Please provide your suggestions.