Question

I am trying to make simple scheduled job in Quartz.NET 2.0

I've read about a similar problem but it didn't work out for me.

The problem is that the job gets executed only once after the StartAt trigger.

Here is my code:

public EntityMappingSvc()
{
    IJobDetail job = JobBuilder.Create<EntityMappingJob>().WithIdentity("QueueJob").Build();
    TriggerBuilder tb = TriggerBuilder.Create();
    tb.WithIdentity("StdTrigger");
    tb.WithSimpleSchedule(a => a.WithIntervalInMinutes(1));
    tb.StartAt(new DateTimeOffset(new DateTime(2012, 11, 20, 10, 55, 0)));
    tb.ForJob(job);
    ITrigger trigger = tb.Build();
    Global.sched.ScheduleJob(job, trigger);
}

protected void Application_Start(object sender, EventArgs e)
{
    Global.factory = new StdSchedulerFactory();
    Global.sched = Global.factory.GetScheduler();
    Global.sched.Start();

    GC.KeepAlive(factory);
    GC.KeepAlive(sched);
}

The job is simple... but to test it i had to raise an error that is caught and handled separate and does not influence the actual job.

After it runs the job the first time, it gets blocked in

while (runnable == null && run)
{
     Monitor.Wait(this, 500);
}
if (runnable != null)
{
     ran = true;
     runnable.Run();
}

in the Run method in SimpleThreadPool.

Any suggestions?

PS: the application is a WCF IIS hosted service.

Edited:

TriggerBuilder tb = TriggerBuilder.Create();
tb.WithIdentity("StdTrigger");
tb.WithCronSchedule("0 1 * * * ?");
tb.StartAt(new DateTimeOffset(new DateTime(2012, 11, 20, 10, 45, 0)));
tb.ForJob(job);
ICronTrigger trigger = tb.Build() as ICronTrigger;
Global.sched.ScheduleJob(job, trigger);

still not working.

same problem.

Was it helpful?

Solution 2

I had a similiar problem. Replace notations:

GC.KeepAlive(factory);
GC.KeepAlive(sched);

with simple static pointer to scheduler:

private static scheduler _scheduler;
...
_scheduler.Start();

OTHER TIPS

I just had the same issue, the reason your original job was only running the first time with the simple schedule is you need to specify .RepeatForever()

tb.WithSimpleSchedule(a => a.WithIntervalInMinutes(1).RepeatForever());

With the cronschedule you don't need to specify reapeatforever but personally I prefer using the simple schedule where possible as it is a lot more readable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top