Quartz.net通过配置文件来完成作业调度

时间:2010-03-12 18:20:35  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:tem;   using System.Collections.Generic;   using System.Text;      using Castle.Core;   using Quartz.Impl;   using Quartz;   using Common.Logging;   using System.Threading;   using System.IO;   using ...
  正文:将Quartz.NET集成到 Castle中 例子代码使用的Quartz.net版本是0.6,Quartz.NET 0.9 发布了 ,最新版本支持通过配置文件来完成后台的作业调度,不必手工创建Trigger和Scheduler。将QuartzStartable 改造如下:
  
  using System;
  using System.Collections.Generic;
  using System.Text;
  
  using Castle.Core;
  using Quartz.Impl;
  using Quartz;
  using Common.Logging;
  using System.Threading;
  using System.IO;
  using Quartz.Xml;
  using System.Collections;
  
  namespace QuartzComponent
  {
   [Transient]
   public class QuartzStartable : IStartable
   {
   private ISchedulerFactory _schedFactory;
   private JobSchedulingDataProcessor processor;
  
   private static ILog log = LogManager.GetLogger(typeof(QuartzStartable));
  
   public QuartzStartable(ISchedulerFactory schedFactory)
   {
   _schedFactory = schedFactory;
   processor = new JobSchedulingDataProcessor(true, true);
   }
  
   public void Start()
   {
   log.Info("Starting service");
   IScheduler sched = _schedFactory.GetScheduler();
  
   //log.Info("------- Scheduling Jobs ----------------");
  
   //// jobs can be scheduled before sched.start() has been called
  
   //// get a "nice round" time a few seconds in the future...
   //DateTime ts = TriggerUtils.GetNextGivenSecondDate(null, 15);
  
   //// job1 will only fire once at date/time "ts"
   //JobDetail job = new JobDetail("job1", "group1", typeof(SimpleQuartzJob));
   //SimpleTrigger trigger = new SimpleTrigger("trigger1", "group1");
   //// set its start up time
   //trigger.StartTimeUtc = ts;
   //// set the interval, how often the job should run (10 seconds here)
   //trigger.RepeatInterval = 10000;
   //// set the number of execution of this job, set to 10 times.
   //// It will run 10 time and exhaust.
   //trigger.RepeatCount = 100;
  
  
   //// schedule it to run!
   //DateTime ft = sched.ScheduleJob(job, trigger);
   //log.Info(string.Format("{0} will run at: {1} and repeat: {2} times, every {3} seconds",
   // job.FullName, ft.ToString("r"), trigger.RepeatCount, (trigger.RepeatInterval / 1000)));
   //log.Info("------- Waiting five minutes... ------------");
  
   //sched.Start();
   Stream s = ReadJobXmlFromEmbeddedResource("MinimalConfiguration.xml");
   processor.ProcessStream(s, null);
   processor.ScheduleJobs(new Hashtable(), sched, false);
   sched.Start();
   try
   {
   // wait five minutes to show jobs
   Thread.Sleep(300 * 1000);
   // executing...
   }
   catch (ThreadInterruptedException)
   {
   }
  
  
   }
  
   private static Stream ReadJobXmlFromEmbeddedResource(string resourceName)
   {
   string fullName = "QuartzComponent." + resourceName; 《Quartz.net通过配置文件来完成作业调度》由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Programming/aspnet/13202.html


关键字:

关于《Quartz.net通过配置文件来完成作业调度》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td