简体   繁体   中英

Quartz.Net cron trigger C#

I'm using Quartz.NET for job scheduling in my ASP.NET application, and I have created one trigger in my global.asax file:

// Code that runs on application startup
ISchedulerFactory schedFact = new StdSchedulerFactory();
// get a scheduler
IScheduler sched = schedFact.GetScheduler();
sched.Start();
// construct job info
JobDetail jobDetail = new JobDetail("mySendMailJob", typeof(SendMailJob));

SimpleTrigger trigger = new SimpleTrigger("myTrigger",
                        null,
                        DateTime.UtcNow,
                        null,
                        SimpleTrigger.RepeatIndefinitely,
                        TimeSpan.FromSeconds(60));

sched.ScheduleJob(jobDetail, trigger);

This code works fine for me and fires after every 1 minute and does my required work.

I tried to create another trigger in this way to fire at a specific time of the day like 10.00 AM, but it's not working for me. I also want to create misfire instructions. Suppose my trigger is not fired on specific time; how do I get misfire instructions to reload my trigger to do the job?

ISchedulerFactory schedFact = new StdSchedulerFactory();
// get a scheduler
IScheduler sched = schedFact.GetScheduler();
sched.Start();
// construct job info
JobDetail jobDetail = new JobDetail("mySendMailJob", typeof(SendMailJob));

Trigger trigger2 = TriggerUtils.MakeDailyTrigger(10, 00);

// schedule the job for execution
//trigger2.Name = "mySendMailTrigger";
sched.ScheduleJob(jobDetail, trigger2);

You can use a cron trigger formula with CronMaker , simple as:

0 0 10 1/1 * ? *

And create a CronTrigger class to use it, see the documentation , sorry, I don't have an example now, but if you can't do I'll post tomorrow.

Can you try to store schedFact in a static variable?

That solved the problem here:

Quartz.Net embedded into Asp.NET MVC2, not firing off jobs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM