Reputation: 67
My objective is to have Quartz.NET execute a job at precisely 25Hz or every 40ms.
I'm using the following trigger:
ITrigger MyTrigger = TriggerBuilder.Create().WithIdentity("T1").ForJob("MyJob").WithSimpleSchedule(x => x.WithInterval(TimeSpan.FromMilliseconds(40)).RepeatForever()).Build();
and the following job:
[DisallowConcurrentExecution]
private class MyJob : Quartz.IJob
{
public void Execute(IJobExecutionContext context)
{
Idx++;
Console.WriteLine("Job {0} fired at {1}ms", Idx, MyStopWatch.ElapsedMilliseconds);
}
}
The problem is that the first 150 executions or so fire too quickly. For example the first 60 iterations all fire at either 20ms or 21ms on the stopwatch. Afterward they fire in bunches every 200ms until it becomes stable around 1000ms, and then starts firing every 40-42ms as intended.
How can I prevent Quartz from triggering a job if the previous job was fired within 40ms?
What is the source of this behavior?
Upvotes: 0
Views: 496
Reputation: 6884
You should not rely on Quartz for millisecond precision scheduling. Quartz has a lot of infrastructure (misfire checks, compensation etc) that will make it unsuitable for this kind of precision.
I'd argue that stable firing on bare virtual machine level could be a challenge too due to GC etc that might pause things a bit.
Quartz can do a lot for you but in this case I'd just go with custom Thread or Timer implementation if these are your requirements.
Upvotes: 2