static void Main(string[] args) { Logger.Instance.Info("Interval Reader Service Started"); try { const string name = "PlayverseReader"; const string description = "Playverse Reader Service "; var host = HostFactory.New(configuration => { configuration.Service<Host>(callback => { callback.ConstructUsing(s => new Host()); callback.WhenStarted(service => service.Start()); callback.WhenStopped(service => service.Stop()); }); configuration.SetDisplayName(name); configuration.SetServiceName(name); configuration.SetDescription(description); configuration.StartAutomatically(); configuration.AfterInstall(() => { ServiceSetup installer = new ServiceSetup(name); installer.StartAfterInstall(); }); configuration.EnableServiceRecovery(rc => { rc.RestartService(0); // restart the service after 1 minute rc.RestartService(0); // restart the service after 1 minute rc.RestartService(0); // restart the service after 1 minute }); }); host.Run(); Console.ReadKey(); } catch (Exception ex) { Logger.Instance.Exception("Reader Service fatal exception. " + ex.Message, ex.StackTrace); ReaderThreads.Shutdown(); Environment.FailFast("READER DIE"); } }
static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.Yellow; logger.Info("Moniverse Writer Service - {0}", DBManager.Instance.GetEnvironment().ToString()); Console.ResetColor(); try { const string name = "MoniverseWriter"; const string description = "Moniverse Writer Service open for biz"; var host = HostFactory.New(configuration => { configuration.Service<Host>(callback => { callback.ConstructUsing(s => new Host()); callback.WhenStarted(service => service.Start()); callback.WhenStopped(service => service.Stop()); }); configuration.SetDisplayName(name); configuration.SetServiceName(name); configuration.SetDescription(description); configuration.StartAutomatically(); configuration.BeforeInstall(() => { //do some stuff here that is relevant }); configuration.AfterInstall(() => { ServiceSetup installer = new ServiceSetup(name); installer.StartAfterInstall(); }); configuration.EnableServiceRecovery(rc => { rc.RestartService(0); // restart the service after 1 minute rc.RestartService(0); // restart the service after 1 minute rc.RestartService(0); // restart the service after 1 minute }); }); host.Run(); } catch (Exception ex) { logger.Error(ex, "Writer Service fatal exception. "); foreach (Thread _thread in Process.GetCurrentProcess().Threads) { _thread.Join(); } Environment.FailFast("DIE"); } Console.ReadKey(); }