I'm using quartz.net 2.3 Jobs are marked with DisallowConcurrentExecution attribute. When a job is launched manually by TriggerJob it does not start if it is already in progress, it's ok. But it starts immediately again when the previous execution is completed. Is it possible to prevent future execution if it was fired when the job is in progress?
Asked
Active
Viewed 2,846 times
3 Answers
2
Yes. You can retrieve all triggers for the job, compare them to the one executing and if they were scheduled after it, unschedule the job (triggers will be deleted).
So, from your job:
public void Execute(IJobExecutionContext context)
{
var currentlyExecutingTrigger = context.Trigger;
var currentlyExecutingJobkey = context.JobDetail.Key;
var newTriggers = context.Scheduler.GetTriggersOfJob(key);
//if trigger was scheduled after currently executing trigger
foreach (var newTrigger in newTriggers)
{
if (newTrigger.StartTimeUtc >= trigger.StartTimeUtc)
{
//delete it
context.Scheduler.UnscheduleJob(newTrigger.Key);
}
}
}

Nick Patsaris
- 2,118
- 1
- 16
- 18
1
How do I keep a Job from firing concurrently?
Quartz.NET 2.x
Implement IJob and also decorate your job class with [DisallowConcurrentExecution] attribute. Read the API documentation for DisallowConcurrentExecutionAttribute for more information.
you can find it in there documentation enter link description here

Kris Nobels
- 1,977
- 2
- 14
- 23
0
I think you're looking for this:
myJobTrigger.MisfireInstruction = MisfireInstruction.CronTrigger.DoNothing;
I haven't tried it, but seems like it works well with the DisallowConcurrentExecution attribute

Community
- 1
- 1

patrickbadley
- 2,510
- 2
- 29
- 30