获取正在Windows服务上运行的调度程序的实例

让我们说我已经准备好Quartz.NET作为Windows服务,它当前正在运行(在Sqlite上运行ADOJobStore )。 我需要在我的Windows应用程序上控制此服务,以便我可以停止它,启动它,添加和删除它的作业等。我怎样才能得到这个调度程序的实例?

很抱歉,如果这听起来像是一个简单的问题,但Quartz.NET上的文档似乎还不够。 只有少数人知道这一点,他们已经有了生命。

更新:我的服务的quartz.config文件

 # You can configure your scheduler in either  configuration section # or in quartz properties file # Configuration section has precedence quartz.threadPool.type = Quartz.Simpl.SimpleThreadPool, Quartz quartz.threadPool.threadCount = 10 quartz.threadPool.threadPriority = Normal # job initialization plugin handles our xml reading, without it defaults are used quartz.plugin.xml.type = Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz quartz.plugin.xml.fileNames = ~/quartz_jobs.xml quartz.scheduler.exporter.type = Quartz.Simpl.RemotingSchedulerExporter, Quartz quartz.scheduler.exporter.port = 555 quartz.scheduler.exporter.bindName = QuartzScheduler quartz.scheduler.exporter.channelType = tcp quartz.scheduler.exporter.channelName = httpQuartz 

我在我的程序中使用的代码来获取调度程序:

 NameValueCollection properties = new NameValueCollection(); properties["quartz.scheduler.instanceName"] = "RemoteClient"; // set thread pool info properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz"; properties["quartz.threadPool.threadCount"] = "10"; properties["quartz.threadPool.threadPriority"] = "Normal"; // set remoting expoter properties["quartz.scheduler.proxy"] = "true"; properties["quartz.scheduler.proxy.address"] = "tcp://127.0.0.1:555/QuartzScheduler"; ISchedulerFactory sf = new StdSchedulerFactory(properties); IScheduler sched = sf.GetScheduler(); 

我的服务已安装并处于已启动状态,它以“本地系统帐户”身份登录,并且可以与桌面进行交互。

您的服务可以通过修改配置文件来公开调度程序:

      

然后,您的Windows应用程序可以使用适当的设置访问它:

  //you can put these in a config file too. NameValueCollection properties = new NameValueCollection(); properties["quartz.scheduler.instanceName"] = "RemoteClient"; // set thread pool info properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz"; properties["quartz.threadPool.threadCount"] = "5"; properties["quartz.threadPool.threadPriority"] = "Normal"; // set remoting expoter properties["quartz.scheduler.proxy"] = "true"; properties["quartz.scheduler.proxy.address"] = "tcp://127.0.0.1:555/QuartzScheduler"; ISchedulerFactory sf = new StdSchedulerFactory(properties); IScheduler sched = sf.GetScheduler(); 

quartz.net master包含了很多你在文档中找不到的好例子。

启动和停止Windows服务与Quartz无关。 似乎有一个.NET API ,但我不熟悉它。

至于添加和删除工作。 您将无法获得Windows服务的调度程序的实例。 有两种方法可以解决它。

  1. 定义WCF合同并在Windows服务中托管WCF服务。 这很简单 。 您不需要IIS也不需要HTTP。 在这种情况下,我建议使用TCP绑定。
  2. 由于您已经在使用ADO作业存储,因此可以将Windows应用程序和Windows服务都设置为Quartz集群:

  

应用程序和Web配置。 如果我没记错的话,不需要额外的代码。 此外,您可以通过设置零大小的线程池来阻止Windows应用程序表单执行作业:

  

现在,您在Windows应用程序中实例化一个调度程序,并使用它来添加和删除作业。 作业将存储在ADO作业存储中,并由Windows服务选取。 显然,app和service必须配置相同的ADO作业setore,并且Windows应用程序必须能够访问sqlite db。

还有一件事。 使用第二种方法,您将无法从Windows应用程序中断正在运行的作业。