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

让我们说我已经准备好Quartz.NET作为 Windows服务,它当前正在运行(在sqlite上运行ADOJobStore).我需要在我的Windows应用程序上控制此服务,以便我可以阻止它,启动它,添加删除它的工作等.我如何获得此调度程序的实例?

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

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

# You can configure your scheduler in either <quartz> 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();

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

解决方法

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

<add key="quartz.scheduler.exporter.type" value="Quartz.Simpl.RemotingSchedulerExporter,Quartz" />
<add key="quartz.scheduler.exporter.port" value="555" />
<add key="quartz.scheduler.exporter.bindName" value="QuartzScheduler" />
<add key="quartz.scheduler.exporter.channelType" value="tcp" />
<add key="quartz.scheduler.exporter.channelName" value="httpQuartz" />

然后,您的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包含您在文档中找不到的非常好的示例.

相关文章

目录简介使用JS互操作使用ClipLazor库创建项目使用方法简单测...
目录简介快速入门安装 NuGet 包实体类User数据库类DbFactory...
本文实现一个简单的配置类,原理比较简单,适用于一些小型项...
C#中Description特性主要用于枚举和属性,方法比较简单,记录...
[TOC] # 原理简介 本文参考[C#/WPF/WinForm/程序实现软件开机...
目录简介获取 HTML 文档解析 HTML 文档测试补充:使用 CSS 选...