protected sealed override void OnStart(string[] args) { OnStarting(args); _host.Start(); OnStarted(); // Register callback for application stopping after we've // started the service, because otherwise we might introduce unwanted // race conditions. _host .Services //.GetRequiredService<IHostApplicationLifetime>() .GetRequiredService <IApplicationLifetime>() .ApplicationStopping .Register(() => { if (!_stopRequestedByWindows) { Stop(); } }); }