I would like that Topshelf stops my service when I debug it in a console.
My code:
public class Program
{
private static ILog _log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public static void Main(string[] args)
{
HostFactory.Run(Configure);
}
/// <summary>
/// Configures the service host.
/// </summary>
/// <param name="cfg">The HostConfigurator</param>
private static void Configure(HostConfigurator cfg)
{
try
{
cfg.Service<ServiceHost>(s =>
{
s.ConstructUsing(name => new ServiceHost());
s.WhenStarted(host => host.StartService());
s.WhenStopped(host => host.StopService());
});
cfg.RunAsLocalSystem();
cfg.StartManually();
cfg.SetDisplayName(DisplayName);
cfg.SetServiceName(ServiceName);
cfg.UseLog4Net();
}
catch (Exception ex)
{
_log.Fatal("Exception on Startup", ex);
throw;
}
}
}
But when I press CTRL+C it hangs in Microsoft.VisualStudio.HostingProcess.HostProc.WaitForThreadExit
.
When I press CTRL+C I would like that host => host.StopService()
is called immediately.
Is that possible?