/// <summary> /// The main entry point for the application. /// </summary> static void Main(string[] args) { if (args.Length == 0) { // Run your service normally. //var service = new RuntimeService(); //service.MainStart(); //System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite); ServiceBase[] ServicesToRun = new ServiceBase[] { new RuntimeService() }; ServiceBase.Run(ServicesToRun); } else if (args.Length >= 1) { var serviceManager = new ServiceManager(RuntimeService.SERVICE_NAME, typeof(RuntimeServiceInstaller)); switch (args[0]) { case "-manual": Properties.Settings.Default.PortNumber = int.Parse(args[1]); var service = new RuntimeService(); service.MainStart(); System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite); break; case "-install": Properties.Settings.Default.PortNumber = int.Parse(args[1]); serviceManager.InstallService(); serviceManager.StartService(new string[] { Properties.Settings.Default.PortNumber.ToString() }); break; case "-uninstall": serviceManager.StopService(); serviceManager.UninstallService(); break; default: throw new NotImplementedException(); } } }