加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 02:03:35 所属栏目:百科 来源:网络整理
导读:让我们说我已经准备好Quartz.NET作为 Windows服务,它当前正在运行(在Sqlite上运行ADOJobStore).我需要在我的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包含您在文档中找不到的非常好的示例.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读