WhenShutdown doesn't appear to be executing

90 views
Skip to first unread message

se...@oneflow.io

unread,
May 24, 2018, 7:23:45 AM5/24/18
to topshelf-discuss
Hi,

WhenStopped appears to work fine when I stop the service, but there is no evidence of either WhenShutdown or WhenStopped executing when I shutdown windows. (I am logging to event viewer and also send a request to honeycomb on both. )

Topshelf config below:

            HostFactory.Run(x =>
            {               
                x.EnableShutdown();
                x.EnableServiceRecovery(configurator =>
                {
                    configurator.RestartService(0);
                    configurator.RestartService(0);
                    configurator.RestartService(0);
                });

                x.Service<IWorkerHost>(s =>
                {
                    s.ConstructUsing(name => container.Resolve<IWorkerHost>());
                    s.WhenStarted(workerHost =>
                    {
                        if (onStart != null) onStart();
                        workerHost.Start();
                    });
                    s.WhenStopped(workerHost =>
                    {
                        workerHost.Stop();
                        if (onStop != null) onStop();
                    });
                    s.WhenShutdown(workerHost =>
                    {
                        workerHost.Shutdown();
                        if (onStop != null) onStop();
                    });
                });

                x.RunAsLocalSystem();

                x.SetStartTimeout(new TimeSpan(0, 0, 2, 0));

                x.SetDescription(String.Format("{0} ({1})", assemblyName, environment));
                x.SetDisplayName(String.Format("{0} ({1})", assemblyName, environment));
                x.SetServiceName(String.Format("{0}_{1}", assemblyName.Replace(".", ""), environment));
            });

I have tried on multiple machines, both windows 10 and server 2016 and am using the latest version of topshelf (v4).
Am I missing something obvious ?

Thanks,
Seán
Reply all
Reply to author
Forward
0 new messages