当我暂停 topshelf 服务时,如何停止或暂停 Quartz.Net?
How can I stop or pause Quartz.Net when I puase topshelf service?
暂停topshelf服务时如何停止或暂停Quartz.Net?
目前在所有示例中,- 注册在 start/stop 方法之外:
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(...)
}
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;
}
}
暂停topshelf服务时如何停止或暂停Quartz.Net?
目前在所有示例中,- 注册在 start/stop 方法之外:
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(...)
}
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;
}
}