Ejemplo n.º 1
0
        /// <summary>
        ///     开启定时任务操作
        /// </summary>
        public void StartTimerQuartzJobs()
        {
            if (_sched == null)
            {
                ISchedulerFactory sf = new StdSchedulerFactory(); //执行者
                _sched = sf.GetScheduler();
            }

            var msg = string.Format("{0} => {1}", DateTime.Now, "正在启动定时任务...");

            SafeSetText(msg, richTimerPush, false);

            //容器处理
            var creaters = WindsorHelper.ResolveAll <JobCreater>();

            foreach (var creater in creaters)
            {
                if (creater.CronExpression == "false")
                {
                    continue;
                }

                msg = string.Format("{0} => {1}", DateTime.Now, "启动任务:" + creater.JobType.FullName + "...");
                SafeSetText(msg, richTimerPush, false);

                //添加定时任务
                AddJobToSchedule(creater.JobType, creater.CronExpression);
            }

            _sched.Start();

            msg = string.Format("{0} => {1}", DateTime.Now, "定时任务启动成功...");
            SafeSetText(msg, richTimerPush, false);
        }
Ejemplo n.º 2
0
        private void FormQuartz_Load(object sender, EventArgs e)
        {
            //容器处理
            var creaters = WindsorHelper.ResolveAll <JobCreater>();

            var panel = new Panel
            {
                Dock       = DockStyle.Fill,
                AutoScroll = true,
                Width      = splitContainer1.Panel1.Width
            };

            var index = 0;

            foreach (var creater in creaters)
            {
                var button = new Button();
                if (creater.CronExpression == "false")
                {
                    button.Text = DoText + LeftImportText + creater.JobType.Name + RightImportText;
                }
                else
                {
                    button.Text = DoTextByScheduler + LeftImportText + creater.JobType.Name + RightImportText;
                }
                button.Tag    = creater;
                button.Click += button_Click;
                button.Width  = panel.Width - 30;
                button.Left   = 10;
                button.Top    = 5 + (index * (5 + button.Height));

                panel.Controls.Add(button);

                index++;
            }

            //添加到Panel
            splitContainer1.Panel1.Controls.Add(panel);

            //开始显示消息
            MessageCenter.PushMessage += MessageCenter_PushMessage;
        }