Quartz.Net Schedular IsStarted 属性 在 UnScheduleJobs、Shutdown、PauseAll、DeleteJobs 和 GetCurrentlyExecutingJob 等之后始终保持为真
Quartz.Net Schedular IsStarted property remains true always after UnScheduleJobs, Shutdown, PauseAll, DeleteJobs and GetCurrentlyExecutingJob etc
我正在使用 Quartz.Net
从代码安排作业。除状态外一切正常。
我想将作业的当前状态显示为 运行 和已停止。
我总是 IsStarted
在计划开始一次后 true
。
如何在停止计划时获取 IsStarted
false
的值?
UnScheduleJobs
、Shutdown
、PauseAll
、DeleteJobs
、GetCurrentlyExecutingJob
这些方法我都试过了。但是没有得到结果。
这是我的代码:
public static class BillScheduleExtension
{
public static List<JobKey> jobKeys = new List<JobKey>();
public static List<TriggerKey> triggerKeys = new List<TriggerKey>();
public static ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
public static IScheduler scheduler = schedulerFactory.GetScheduler();
public static bool SchdularStarted()
{
return scheduler.IsStarted;
}
public static void StopSchduleProcess()
{
if (triggerKeys.Count > 0)
{
//scheduler.DeleteJobs(jobKeys);
//scheduler.Shutdown();
scheduler.UnscheduleJobs(triggerKeys);
scheduler.PauseAll();
//scheduler.IsStarted = false;
//foreach (var jbkey in jobKeys)
//{
// scheduler.Interrupt(jbkey);
//}
}
}
public static void StartSchduleProcess(Session ss)
{
XPQuery<BillSchedule> _schedule = new XPQuery<BillSchedule>(ss);
try
{
var count = 0;
foreach (BillSchedule bs in _schedule)
{
JobDataMap jm = new JobDataMap();
jm.Put("jobsession", ss);
IJobDetail job = JobBuilder.Create<BillJob>()
.WithIdentity("BillJob" + count.ToString(), null)
.SetJobData(jm)
.Build();
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("Billtrigger" + count.ToString(), null)
.WithDailyTimeIntervalSchedule(x => x.WithIntervalInMinutes(bs.Day))
.Build();
triggerKeys.Add(trigger.Key);
scheduler.ScheduleJob(job, trigger);
count++;
}
scheduler.Start();
}
catch (Exception ex)
{
throw;
}
}
}
我们将不胜感激。
IScheduler.IsStarted
属性
This only reflects whether Start() has ever been called on this Scheduler, so it will return true even if the IScheduler is currently in standby mode or has been since shutdown.
也许你应该检查 属性 IsShutdown
和 InStandbyMode
。
我正在使用 Quartz.Net
从代码安排作业。除状态外一切正常。
我想将作业的当前状态显示为 运行 和已停止。
我总是 IsStarted
在计划开始一次后 true
。
如何在停止计划时获取 IsStarted
false
的值?
UnScheduleJobs
、Shutdown
、PauseAll
、DeleteJobs
、GetCurrentlyExecutingJob
这些方法我都试过了。但是没有得到结果。
这是我的代码:
public static class BillScheduleExtension
{
public static List<JobKey> jobKeys = new List<JobKey>();
public static List<TriggerKey> triggerKeys = new List<TriggerKey>();
public static ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
public static IScheduler scheduler = schedulerFactory.GetScheduler();
public static bool SchdularStarted()
{
return scheduler.IsStarted;
}
public static void StopSchduleProcess()
{
if (triggerKeys.Count > 0)
{
//scheduler.DeleteJobs(jobKeys);
//scheduler.Shutdown();
scheduler.UnscheduleJobs(triggerKeys);
scheduler.PauseAll();
//scheduler.IsStarted = false;
//foreach (var jbkey in jobKeys)
//{
// scheduler.Interrupt(jbkey);
//}
}
}
public static void StartSchduleProcess(Session ss)
{
XPQuery<BillSchedule> _schedule = new XPQuery<BillSchedule>(ss);
try
{
var count = 0;
foreach (BillSchedule bs in _schedule)
{
JobDataMap jm = new JobDataMap();
jm.Put("jobsession", ss);
IJobDetail job = JobBuilder.Create<BillJob>()
.WithIdentity("BillJob" + count.ToString(), null)
.SetJobData(jm)
.Build();
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("Billtrigger" + count.ToString(), null)
.WithDailyTimeIntervalSchedule(x => x.WithIntervalInMinutes(bs.Day))
.Build();
triggerKeys.Add(trigger.Key);
scheduler.ScheduleJob(job, trigger);
count++;
}
scheduler.Start();
}
catch (Exception ex)
{
throw;
}
}
}
我们将不胜感激。
IScheduler.IsStarted
属性
This only reflects whether Start() has ever been called on this Scheduler, so it will return true even if the IScheduler is currently in standby mode or has been since shutdown.
也许你应该检查 属性 IsShutdown
和 InStandbyMode
。