protected override void OnShutdown() { this.RequestAdditionalTime(5 * 60 * 1000); Threads.StopAllThreads(); T.Join(); base.OnShutdown(); }
static int Main(string[] args) { Init(); for (int i = 0; i < args.Length; i++) { if (args[i].ToLower() == "-reset") { Console.WriteLine("Resetting"); FoxEventLog.WriteEventLog("RESET: Recovering from a crash", EventLogEntryType.Warning); try { ServiceController ctrl = new ServiceController("FoxSDCA"); ctrl.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 5, 0)); ctrl.Start(); } catch (Exception ee) { Console.WriteLine(ee.ToString()); return(-1); } return(0); } if (args[i].ToLower() == "-install") { try { ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location }); } catch (Exception ee) { Console.WriteLine(ee.ToString()); return(-1); } return(0); } if (args[i].ToLower() == "-pipeaction") { if (args.Length <= i) { return(-1); } PipeGUID = args[i + 1]; UsePipeAction = true; i++; SMain(); return(0); } if (args[i].ToLower() == "-screen") { if (args.Length <= i) { return(-1); } PipeGUID = args[i + 1]; UseScreenAction = true; i++; SMain(); return(0); } if (args[i].ToLower() == "-autodnsconfig") { UseDNSAutoConfig = true; i++; SMain(); return(0); } if (args[i].ToLower() == "-recovercreds") { UseLoginRecovery = true; i++; SMain(); return(0); } } #if DEBUG && !DEBUGSERVICE SMain(); Console.WriteLine("DEBUG: Running - Press any key . . . "); Console.ReadKey(true); Console.WriteLine("DEBUG: Stopping . . . "); Threads.StopAllThreads(); #else ServicesToRun = new ServiceBase[] { service }; ServiceBase.Run(ServicesToRun); #endif return(0); }