Beispiel #1
0
 public WindowsService(ExceptionGeneratorService service, TimeSpan timeout)
 {
     _computerService = service;
     Task.Delay(timeout).ContinueWith(t => Stop());
 }
Beispiel #2
0
        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 | --scenario Scenario]");
            Console.WriteLine();

            EnvironmentInfo.PrintDescriptionToConsole();

            ParseCommandLine(args, out TimeSpan timeout, out var scenario, out bool runAsService);

            var exceptionGeneratorService = new ExceptionGeneratorService();

            if (runAsService)
            {
                exceptionGeneratorService.RunAsService(timeout);
            }
            else
            {
                if (scenario != null)
                {
                    switch (scenario.Value)
                    {
                    case Scenario.ExceptionsProfilerTest:
                        new ExceptionsProfilerTestScenario().Run();

                        // TODO: Remove the sleep when flush on shutdown is implemented in the profiler
                        Console.WriteLine(" ########### Sleeping for 10 seconds");
                        Thread.Sleep(10_000);
                        break;

                    case Scenario.ParallelExceptions:
                        new ParallelExceptionsScenario().Run();

                        // TODO: Remove the sleep when flush on shutdown is implemented in the profiler
                        Console.WriteLine(" ########### Sleeping for 20 seconds");
                        Thread.Sleep(20_000);
                        break;

                    case Scenario.Sampling:
                        new SamplingScenario().Run();

                        // TODO: Remove the sleep when flush on shutdown is implemented in the profiler
                        Console.WriteLine(" ########### Sleeping for 20 seconds");
                        Thread.Sleep(20_000);
                        break;

                    default:
                        Console.WriteLine($" ########### Unknown scenario: {scenario}.");
                        break;
                    }
                }
                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}");
            }
        }