C#使用石英实时配置间隔帮助
作者:互联网
我需要使时间间隔取决于数据库配置.
因此,例如,控制台应用程序以10秒的间隔运行,如果我将间隔更改为20秒,它将遵循新间隔而不关闭控制台应用程序.
这是当前配置:
NameValueCollection properties = new NameValueCollection();
properties["quartz.threadPool.threadCount"] = "1";
ISchedulerFactory schedFact = new StdSchedulerFactory(properties);
IScheduler sched = schedFact.GetScheduler();
sched.Start();
// define the job and tie it to our HelloJob class
IJobDetail job = JobBuilder.Create<Run>()
.WithIdentity("myJob", "group1") // name "myJob", group "group1"
.Build();
// Trigger the job to run now, and then every 30 seconds
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("myTrigger", "group1")
.StartNow()
.WithSimpleSchedule(f => f.WithIntervalInSeconds(10)
.RepeatForever())
.WithPriority(1)
.Build();
// Tell quartz to schedule the job using our trigger
sched.ScheduleJob(job, trigger);
解决方法:
根据Quartz.NET manual,您始终可以通过重新安排新触发器来更改现有触发器:
// retrieve the trigger
Trigger oldTrigger = sched.getTrigger(triggerKey("oldTrigger", "group1");
// obtain a builder that would produce the trigger
TriggerBuilder tb = oldTrigger.getTriggerBuilder();
// update the schedule associated with the builder, and build the new trigger
// (other builder methods could be called, to change the trigger in any desired way)
Trigger newTrigger = tb.withSchedule(simpleSchedule()
.withIntervalInSeconds(10)
.withRepeatCount(10)
.build();
sched.rescheduleJob(oldTrigger.getKey(), newTrigger);
标签:quartz-net,quartz-scheduler,c 来源: https://codeday.me/bug/20191119/2033747.html