using Quartz.Impl; using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.ServiceProcess; using System.Text; using System.Threading.Tasks; using Topshelf; namespace DSWeb.EventBus { class Program { static void Main(string[] args) { var serviceName = ConfigurationManager.AppSettings["ServiceName"]; var serviceDisplayName = ConfigurationManager.AppSettings["ServiceDisplayName"]; if (Environment.UserInteractive) { Console.Title = serviceDisplayName; } Host host = HostFactory.New(x => { // 基本的配置 x.RunAsLocalSystem(); x.SetServiceName(serviceName); x.SetDisplayName(serviceDisplayName); x.StartAutomaticallyDelayed(); x.EnableShutdown(); // 注册服务 x.Service(hostSettings => new EventProcessService()); // 设置服务失败后的操作,分别对应第一次、第二次、后续 x.EnableServiceRecovery(t => { t.RestartService(0); t.RestartService(0); t.RestartService(0); t.OnCrashOnly(); }); }); host.Run(); } } }