public static void Main(string[] args) { Console.WriteLine($"Starting at {DateTime.UtcNow}"); Console.WriteLine($"{Environment.NewLine}Usage:{Environment.NewLine} > {Process.GetCurrentProcess().ProcessName} [--service] [--timeout TimeoutInSeconds | --run-infinitely]"); Console.WriteLine(); EnvironmentInfo.PrintDescriptionToConsole(); ParseCommandLine(args, out TimeSpan timeout, out bool runAsService); var exceptionGeneratorService = new ExceptionGeneratorService(); if (runAsService) { exceptionGeneratorService.RunAsService(timeout); } else { if (timeout == TimeSpan.MinValue) { Console.WriteLine($" ########### The application will run interactively because no timeout was specified or could be parsed."); exceptionGeneratorService.StartService(); Console.WriteLine($"{Environment.NewLine} ########### Press enter to finish."); Console.ReadLine(); exceptionGeneratorService.StopService(); Console.WriteLine($"{Environment.NewLine} ########### Press enter to terminate."); Console.ReadLine(); } else { Console.WriteLine($" ########### The application will run non-interactively for {timeout} and will stop after that time."); exceptionGeneratorService.StartService(); Thread.Sleep(timeout); exceptionGeneratorService.StopService(); } Console.WriteLine($"{Environment.NewLine} ########### Finishing run at {DateTime.UtcNow}"); } }
protected override void OnStop() { _computerService.StopService(); base.OnStop(); }