2017-05-03 3 views
1

topshelf 서비스를 일시 중지 할 때 Quartz.Net을 중지하거나 일시 중지 할 수 있습니까? 모든 예에서 현재 topshelf 서비스를 푸시 할 때 Quartz.Net을 멈추거나 일시 중지하려면 어떻게합니까?

는, - 등록 외부 시작이다/중지 방법 :

factory.Service<IServiceHost>(sc => 
{ 
    sc.ConstructUsing(s => new ServiceHost()); 
    sc.WhenStarted((s, host) => s.Start(host)); 
    sc.WhenStopped(s => s.Stop()); 
    sc.WhenPaused(s => s.Pause()); 
    sc.WhenContinued(s => s.Continue()); 

    sc.ScheduleQuartzJob(...) 
} 
+0

'에 대해 말하는 무엇 Scheduler.Shutdown()'? – Rabban

답변

0

Program.cs

 HostFactory.Run(factory => 
     { 
      factory.UseNLog(); 
      factory.UseAutofacContainer(Container); 
      factory.Service<ServiceHost>(service => 
      { 
       service.ConstructUsingAutofacContainer(); 
       service.WhenStarted((sc, hc) => sc.Start(hc)); 
       service.WhenStopped((sc, hc) => 
       { 
        Container.Dispose(); 
        return sc.Stop(hc); 
       }); 

       service.ScheduleQuartzJob(cfg => JobConfigurator.GetConfigurationForJob<DataImportJob>(cfg, Settings.Default.RecurrentTimeout)); 

       factory.RunAsLocalSystem().StartAutomaticallyDelayed().EnableServiceRecovery(sr => 
      { 
       sr.OnCrashOnly(); 
       sr.RestartService(0); 
       sr.SetResetPeriod(1); 
      }).EnableShutdown(); 
     }); 

ServiceControl.cs :

public class ServiceHost : ServiceControl 
{ 
    private readonly IScheduler _scheduler; 

    public CdcServiceHost(IScheduler scheduler) 
    { 
     Ensure.Argument.NotNull(scheduler); 
     _scheduler = scheduler; 
    } 

    public bool Start(HostControl hostControl) 
    { 
     if (!_scheduler.IsStarted) 
     { 
      _scheduler.Start(); 
     } 

     Logger.Log.Debug("Service was started"); 
     return true; 
    } 

    public bool Stop(HostControl hostControl) 
    { 
     Logger.Log.Debug("Stopping scheduler"); 
     _scheduler.Shutdown(true); 

     Logger.Log.Debug("Service was stopped"); 
     return true; 
    } 
} 
관련 문제