I am seeing different behaviour in Topshelf depending on whether I start the application in standalone mode or installed as a service. I have tried Topshelf 3.3.1 and 4.1.
I am using a service that implements ServiceControl, which works fine in standalone mode. When trying to start the installed service, I receive the message that the service took too long to respond to control requests.
var resultCode = HostFactory.Run(x =>
{
x.Service<ServiceControl>(sc =>
{
sc.ConstructUsing(() =>
{
Console.WriteLine("GET INSTANCE!");
return new WorkerService();
});
sc.WhenStarted((s, h) =>
{
Console.WriteLine("START!");
return s.Start(h);
});
sc.WhenStopped((s, h) =>
{
Console.WriteLine("STOP!");
return s.Stop(h);
});
sc.BeforeStartingService(() => Console.WriteLine("BEFORE START!"));
});
x.SetDescription("WorkerService");
x.SetDisplayName("WorkerService");
x.SetServiceName("WorkerService");
});
This is a very verbose version of calling a service (with lots of console output), but even the calls to ConstructUsing
or BeforeStartingService
do not produce any console output, while log calls inside the Service<>
lambda produce output.
I am left quite clueless here, but also have not been able to reproduce this with a minimal sample. The timeout comes after about 3-4 seconds, without any visible attempt to start the service. Starting the service thread from the program main does work without exception.
Starting the service with WorkerService.exe
works as expected, starting it with WorkerService.exe start
(which starts the service) does not work.
As this happens with Topshelf 3 and 4, it most likely is something I am doing wrong inside the application. Any pointer into the right direction is very much appreciated.
ConstructUsing
lambda (so there is no console log), but only as service, not in standalone - philip