简体   繁体   English

当前作业完成后关闭Quartz调度程序

[英]Shutdown Quartz scheduler after current jobs complete

I am using Quartz for job scheduling in a Windows service. 我在Windows服务中使用Quartz进行作业调度。 I need to shutdown the scheduler when the service is stopped or when the user changes the frequency of the job runs. 服务停止或用户更改作业运行频率时,我需要关闭调度程序。 As I would like to wait for the executing jobs, I use 因为我想等待正在执行的作业,所以我使用

scheduler.Shutdown(true);

I get in both cases the exception: 在这两种情况下,我都有例外:

Quartz.UnableToInterruptJobException: Job 'myJob' can not be interrupted, since it does not implement Quartz.IInterruptableJob Quartz.UnableToInterruptJobException:无法中断作业“ myJob”,因为它未实现Quartz.IInterruptableJob

The running service cannot be stopped which is quite bad. 无法停止正在运行的服务,这非常糟糕。

But job interruption means not waiting for the job to complete? 但是工作中断意味着不等待工作完成吗? So, not what I want? 所以,不是我想要的吗? Although it would solve the current exception problems. 虽然它可以解决当前的异常问题。

What would be the correct implementation not causing shutdown to crash? 什么是不会导致shutdown崩溃的正确实现?

And if I really need to implement IInterruptableJob, how is this done? 如果我真的需要实现IInterruptableJob,该怎么做? I don't find a tutorial about that and I don't really want to do anything different than a standard shutdown. 我没有找到有关此的教程,并且我真的不想做与标准关机不同的任何事情。 I am using the standard scheduler factory for the scheduler creation: 我正在使用标准调度程序工厂进行调度程序创建:

schedulerFactory = new StdSchedulerFactory();
scheduler = schedulerFactory.GetScheduler();

I found how to interrupt the job... I simply had to implement the IInteruptableJob interface, with an interrupt method doing nothing. 我找到了如何中断工作的方法...我只需要实现IInteruptableJob接口,而interrupt方法却什么也不做。 This post helped me a lot! 这篇文章对我有很大帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM