2009-09-10 12 views

답변

2

더 일반적인 방법은 IInterruptableJob을 사용하는 것입니다 (http://quartznet.sourceforge.net/faq.html#howtostopjob 참조). 물론 이것은 (! jobRunning) if (! jobRunning)를 말하는 또 다른 방법입니다.

+0

은 한 번에 허용 된 IInterruptableJob을 구현하는 해당 클래스의 하나의 인스턴스이거나 해당 클래스를 사용하는 작업입니까? –

+2

한 번에 하나의 인스턴스 만 허용하려는 경우 IStatefulJob은 프라이드 한 http://quartznet.sourceforge.net/faq.html#howtopreventconcurrentfire입니다. IInterruptableJob은 인터럽트 신호를 보내는 표준 방법을 제공하며 작업 측면에서 무거워 할 필요가 있습니다 (중단 플래그가 발생했는지 확인). –

1

작업이 시작될 때 일종의 전역 변수 (jobRunning = true)를 설정하지 않고 작업이 완료되면 다시 되돌릴 수 있습니까? (거짓 jobRunning ==)

+0

예, 종종 가장 간단한 해결책이 가장 좋습니다. 나는 이것을 구현했는데, 첫 번째 작업이 완료 될 때까지 작업을 일시 중지 한 구현 된 솔루션이 있지만,이 작업은 정상적으로 작동합니다! –

0

앱 시작시 작업 목록에서 자신을 제거하고 종료 자체를 삽입 할 수있는 경우

그런 다음 트리거 화재, 당신의 코드를 실행하면.

0

요즘에는 "WithMisfireHandlingInstructionIgnoreMisfires"를 트리거에 사용하고 작업에서 [DisallowConcurrentExecution] 특성을 사용할 수 있습니다.

0

이것은 구현 한 것입니다 (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())); 
    } 
} 
관련 문제