/// <summary> /// The main entry point for the application. /// </summary> static void Main() { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); var ser = new Service1(); if (Environment.UserInteractive) { _handler = (eventType) => { //only 5 seconds so run important code first if (eventType == 2) { ser.Stop(); LogManager.Logger.Debug("Exiting"); } return false; }; SetConsoleCtrlHandler(_handler, true); ser.Start(null); Thread.Sleep(Timeout.Infinite); } else { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { ser }; ServiceBase.Run(ServicesToRun); } }
/// <summary> /// The main entry point for the application. /// </summary> static void Main() { var service = new Service1(); #if DEBUG service.DebugMode(); Thread.Sleep(Timeout.Infinite); #else log4net.Config.XmlConfigurator.Configure(); ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { service }; ServiceBase.Run(ServicesToRun); #endif }