gpt4 book ai didi

C#帮助使用 quartz 实时配置间隔

转载 作者:行者123 更新时间:2023-11-30 16:04:26 25 4
gpt4 key购买 nike

我需要根据数据库配置设置时间间隔。

例如,控制台应用程序以 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);

关于C#帮助使用 quartz 实时配置间隔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34988335/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com