让我们说我已经准备好Quartz.NET作为
Windows服务,它当前正在运行(在sqlite上运行ADOJobStore).我需要在我的Windows应用程序上控制此服务,以便我可以阻止它,启动它,添加和删除它的工作等.我如何获得此调度程序的实例?
很抱歉,如果这听起来像是一个简单的问题,但Quartz.NET上的文档似乎还不够.只有少数人知道这一点,他们已经有了生命.
# 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包含您在文档中找不到的非常好的示例.