Reputation: 1617
I'm using the Quartz.Net Library. I wrote some trigger:
var t =
TriggerBuilder.Create()
.WithIdentity("FirstTask", "TaskGroup")
.StartAt(DateBuilder.TodayAt(16, 17, 0))
.EndAt(DateBuilder.TodayAt(17, 17, 0))
.WithSimpleSchedule(x => x.RepeatForever()
.WithIntervalInSeconds(1))
.Build();
If I exclude .WithIntervalInSeconds(1)
I have an exception that the retry time can't be zero. So, how can I restart my job when it has finished? Also I didn't find the quartz.net configure file to set maximum threads for it.
Upvotes: 0
Views: 799
Reputation: 1617
Much easier than it looked at first:
var job = JobBuilder.Create<HelloJob>().WithIdentity(new JobKey("Task_1", "TaskGroup")).Build();
var t = TriggerBuilder.Create()
.WithIdentity("Trigger_1", "TaskGroup")
.StartAt(DateBuilder.TodayAt(21, 15, 0))
.EndAt(DateBuilder.TodayAt(21, 18, 0))
.Build();
_scheduleService.Scheduler.ScheduleJob(job, t);
And implementing method in listiner:
public void JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException)
{
if (DateTime.UtcNow > context.Trigger.EndTimeUtc)
return;
context.Scheduler.RescheduleJob(context.Trigger.Key, context.Trigger);
}
Upvotes: 0
Reputation: 8725
In my previous job we configure Quartz threadpool
as the following:
quartz.threadPool.threadCount = 3
Read more about it in Configuration section.
@stuartd provide an answer to your question here.
Take his answer and then change the trigger to use StartNow
method:
var trigger = TriggerBuilder.Create()
.WithIdentity(triggerKey)
.startNow()
.build();
@SchlaWiener also provide a nice solution using TopShelf
.
Upvotes: 1
Reputation: 24903
To set max thread count to 50:
var properties = new NameValueCollection { { @"quartz.threadPool.threadCount", @"50" } };
var factory = new StdSchedulerFactory(properties);
var scheduler = schedulerFactory.GetScheduler();
And do not exclude WithIntervalInSeconds
, Quartz must know, when to run again
Upvotes: 2