public static int Main(string[] args)
        {
            try {
                XmlConfigurator.Configure();
                GlobalContext.Properties["Version"]          = Assembly.GetExecutingAssembly().GetName().Version;
                ConnectionHelper.DefaultConnectionStringName = "production";
                ActiveRecordInitialize.Init("production", typeof(Job).Assembly);
                var config = new Config();
                ConfigReader.LoadSettings(config);

                var runner = new JobRunner();
                runner.Jobs.Add(new CalculatorJob(config));

                var cmd = args.FirstOrDefault();

                if (cmd.Match("uninstall"))
                {
                    CommandService.Uninstall();
                    return(0);
                }

                if (cmd.Match("install"))
                {
                    CommandService.Install();
                    return(0);
                }
                if (cmd.Match("console"))
                {
                    runner.Start();
                    if (Console.IsInputRedirected)
                    {
                        Console.WriteLine("Для завершения нажмите ctrl-c");
                        Console.CancelKeyPress += (e, a) => runner.Stop();
                        runner.Cancellation.WaitHandle.WaitOne();
                    }
                    else
                    {
                        Console.WriteLine("Для завершения нажмите любую клавишу");
                        Console.ReadLine();
                        runner.Stop();
                    }
                    runner.Join();
                    return(0);
                }

                ServiceBase.Run(new CommandService(runner));
                return(0);
            }
            catch (Exception e) {
                log.Error("Ошибка при запуске приложения", e);
                return(1);
            }
        }
        public void Cancel_work()
        {
            var barier    = new Barrier(2);
            var jobRunner = new JobRunner();

            jobRunner.TestJobs = new List <Job> {
                new Job(typeof(ActionJob).Name, 1.Second())
            };
            jobRunner.Jobs = new List <IJob> {
                new ActionJob(t => {
                    barier.SignalAndWait();
                    t.WaitHandle.WaitOne();
                })
            };

            jobRunner.Start();
            barier.SignalAndWait();
            jobRunner.Stop();
            Assert.IsTrue(jobRunner.Join());
        }