使用Quartz.net動態設定定時時間問題

來源:互聯網
上載者:User

標籤:style   blog   color   io   使用   ar   div   art   sp   

關於使用Quartz.net就不用解釋了。。

應客戶需求問題。。需要將做一個介面設定定時的時間。因此我在百度一番。。用CronExpression類可以設定時間。。。

我知道這個類有定義好的欄位。。不知道是不是我用的方式不對。。反正我沒找到。。

於是我就這麼乾的。。

 /// <summary>        /// 定時方法        /// </summary>        /// <param name="week">天</param>        /// <param name="hour">時</param>        /// <param name="minute">分</param>        private void Timing(string week, string hour, string minute)        {            IScheduler sched1;            ISchedulerFactory sf1 = new StdSchedulerFactory();            sched1 = sf1.GetScheduler();            JobKey jobkey1 = new JobKey("myjob1", "mygroup1");            IJobDetail job1 = JobBuilder.Create<WebDemo.quartz>().WithIdentity(jobkey1).Build();            string t = "";            if (week == "*")            {                //每天                t = "0 " + minute + " " + hour + " ? * *";//每天的某時某分0秒            }            else            {                //某天                t = "0 " + minute + " " + hour + " ? * " + week;//某天的某時某分0秒            }            CronExpression cron = new CronExpression(t);            IOperableTrigger trigger1 = new CronTriggerImpl("trigName1", "group12", cron.CronExpressionString);            sched1.ScheduleJob(job1, trigger1);            sched1.Start();        }

然後就OK了。。嘿嘿。。

使用Quartz.net動態設定定時時間問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.