/// <summary> /// The main entry point for the application. /// </summary> static void Main() { var environment = System.Configuration.ConfigurationManager.AppSettings["Environment"].ToString(); var logFilePath = System.Configuration.ConfigurationManager.AppSettings["LogFilePath"].ToString(); LogService(String.Format("Environment: '{0}'", environment)); LogService(String.Format("Log file path: '{0}'", logFilePath)); if (Environment.UserInteractive) { LogService("Running mode: 'Interactive'"); var service = new Service1(); service.OnStart(new string[] { "" }); LogService("NOTE: You can press any key at any time to exit ..."); Console.ReadLine(); service.OnStop(); } else { LogService("Running mode: 'As a Service'"); var service = new Service1(); Run(service); } }
static void Main(string[] args) { var service = new Service1(); if (Debugger.IsAttached) { service.OnStart(args); Console.WriteLine("Find the any key!"); Console.Read(); service.OnStop(); } else { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { service }; ServiceBase.Run(ServicesToRun); } }