Source Code-1.6Mhtml
上篇已經瞭解Quartz.NET的基本使用方法了。但若是想方便的知道某個做業執行狀況,須要暫停,啓動等操做行爲,這時候就須要個Job管理的界面。git
本文介紹Quartz.NET如何進行遠程job管理,如圖:github
一:做業服務端web
static void Main(string[] args) { var properties = new NameValueCollection(); properties["quartz.scheduler.instanceName"] = "RemoteServerSchedulerClient"; // 設置線程池 properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz"; properties["quartz.threadPool.threadCount"] = "5"; properties["quartz.threadPool.threadPriority"] = "Normal"; // 遠程輸出配置 properties["quartz.scheduler.exporter.type"] = "Quartz.Simpl.RemotingSchedulerExporter, Quartz"; properties["quartz.scheduler.exporter.port"] = "556"; properties["quartz.scheduler.exporter.bindName"] = "QuartzScheduler"; properties["quartz.scheduler.exporter.channelType"] = "tcp"; var schedulerFactory = new StdSchedulerFactory(properties); var scheduler = schedulerFactory.GetScheduler(); var job = JobBuilder.Create<PrintMessageJob>() .WithIdentity("myJob", "group1") .Build(); var trigger = TriggerBuilder.Create() .WithIdentity("myJobTrigger", "group1") .StartNow() .WithCronSchedule("/10 * * ? * *") .Build(); scheduler.ScheduleJob(job, trigger); scheduler.Start(); }
public class PrintMessageJob : IJob { public void Execute(IJobExecutionContext context) { Console.WriteLine("Hello!"); } }
啓動以下tcp
二:做業遠程管理端,無需寫任何代碼,引用官方程序集,嵌入到已有的web網站。 ide
PM> Install-Package CrystalQuartz.Remote網站
Webconfig 須要配置的地方ui
<configuration> <crystalQuartz> <provider> <add property="Type" value="CrystalQuartz.Core.SchedulerProviders.RemoteSchedulerProvider, CrystalQuartz.Core" /> <add property="SchedulerHost" value="tcp://127.0.0.1:556/QuartzScheduler" /> <!--TCP監聽的地址--> </provider> </crystalQuartz> <system.webServer> <!-- Handler攔截處理了,輸出做業監控頁面--> <handlers> <add name="CrystalQuartzPanel" verb="*" path="CrystalQuartzPanel.axd" type="CrystalQuartz.Web.PagesHandler, CrystalQuartz.Web" /> </handlers> </system.webServer> </configuration>
Web管理界面線程
CrystalQuartz 提供基礎功能,能夠繼續在此基礎上進行二次開發,另外推薦使用Window服務寄宿,比較方法。orm
張善友 http://www.cnblogs.com/shanyou/archive/2012/01/15/2323011.html
CrystalQuartz開源的地址 https://github.com/guryanovev/CrystalQuartz