문제
Quartz.net에서 꽤 자주 트리거하고 때로는 오래 실행되는 작업을 수행합니다. 작업이 이미 실행중인 경우 트리거를 어떻게 취소합니까?
해결책
보다 표준적인 방법은 iinterruptableJob을 사용하는 것입니다. http://quartznet.sourceforge.net/faq.html#howtostopjob . 물론 이것은 (! jobrunning)을 말하는 또 다른 방법입니다.
다른 팁
작업이 시작될 때 일종의 글로벌 변수 (jobrunning = true)를 설정하고 완료되면 False로 되돌릴 수 있습니까?
그런 다음 트리거가 발생하면 코드를 실행하면 (jobrunning == false)
앱은 시작시 작업 목록에서 스스로를 제거하고 종료시 자체를 삽입 할 수 있습니다.
요즘 당신은 트리거에서 "withmisfireHandlingIntructionIGNOREMISFIRES"를 사용할 수 있으며 직무에서 [allallowCurrentExecution] 속성을 사용할 수 있습니다.
이것은 나의 구현이었습니다 (Markol이 이전에 제공 한 링크의 제안을 사용).
나는 단지 타이핑을 저장하려고 노력하고 있습니다.
나는 quartz.net에서 새롭기 때문에 소금 기차로 아래를 가져 가라.
public class AnInterruptableJob : IJob, IInterruptableJob
{
private bool _isInterrupted = false;
private int MAXIMUM_JOB_RUN_SECONDS = 10;
/// <summary>
/// Called by the <see cref="IScheduler" /> when a
/// <see cref="ITrigger" /> fires that is associated with
/// the <see cref="IJob" />.
/// </summary>
public virtual void Execute(IJobExecutionContext context)
{
/* See http://aziegler71.wordpress.com/2012/04/25/quartz-net-example/ */
JobKey key = context.JobDetail.Key;
JobDataMap dataMap = context.JobDetail.JobDataMap;
int timeOutSeconds = dataMap.GetInt("TimeOutSeconds");
if (timeOutSeconds <= 0)
{
timeOutSeconds = MAXIMUM_JOB_RUN_SECONDS;
}
Timer t = new Timer(TimerCallback, context, timeOutSeconds * 1000, 0);
Console.WriteLine(string.Format("AnInterruptableJob Start : JobKey='{0}', timeOutSeconds='{1}' at '{2}'", key, timeOutSeconds, DateTime.Now.ToLongTimeString()));
try
{
Thread.Sleep(TimeSpan.FromSeconds(7));
}
catch (ThreadInterruptedException)
{
}
if (_isInterrupted)
{
Console.WriteLine("Interrupted. Leaving Excecute Method.");
return;
}
Console.WriteLine(string.Format("End AnInterruptableJob (should not see this) : JobKey='{0}', timeOutSeconds='{1}' at '{2}'", key, timeOutSeconds, DateTime.Now.ToLongTimeString()));
}
private void TimerCallback(Object o)
{
IJobExecutionContext context = o as IJobExecutionContext;
if (null != context)
{
context.Scheduler.Interrupt(context.FireInstanceId);
}
}
public void Interrupt()
{
_isInterrupted = true;
Console.WriteLine(string.Format("AnInterruptableJob.Interrupt called at '{0}'", DateTime.Now.ToLongTimeString()));
}
}
제휴하지 않습니다 StackOverflow