.net Quartz程序的使用

  
  
  
  
  1. public class ManInfo 
  2.     { 
  3.         static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(InfoBLL)); 
  4.         public static void Start() 
  5.         { 
  6.             ISchedulerFactory _schedFactory = new StdSchedulerFactory(); 
  7.   
  8.             logger.Info("开始执行程序"); 
  9.             try 
  10.             { 
  11.                 //计划任务 
  12.                 IScheduler sched = _schedFactory.GetScheduler(); 
  13.                 JobSchedulingDataProcessor processor = new JobSchedulingDataProcessor(truetrue); 
  14.                 Stream s = new FileStream(AppDomain.CurrentDomain.BaseDirectory + (@"macher-setting.xml"), FileMode.Open); 
  15.                 processor.ProcessStream(s, null); 
  16.                 processor.ScheduleJobs(new Hashtable(), sched, false); 
  17.                 sched.Start(); 
  18.             } 
  19.             catch (Exception ex) 
  20.             { 
  21.                 logger.Error("Application_Start:" + ex); 
  22.             } 
  23.   
  24.         } 
  25.     } 

记得要引用QuartZ.dll

  
  
  
  
  1. public class InfoBLL : IJob 
  2.     { 
  3.         static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(InfoBLL)); 
  4.         void IJob.Execute(JobExecutionContext context) 
  5.         { 
  6.   
  7.             logger.Info("开始更改信息状态"); 
  8.             Import(); 
  9.   
  10.             logger.Info("开始修复更改出现的信息"); 
  11.             repair(); 
  12.   
  13.             // System.Threading.WaitCallback waitCallback = new WaitCallback(BindWLT); 
  14.             //ThreadPool.QueueUserWorkItem(waitCallback, arr); 
  15.             //ThreadPool.QueueUserWorkItem(waitCallback, arr1); 
  16.         } 

 记得一定要继承接口!

最重要的要配置:

 

  
  
  
  
  1. <?xml version="1.0" encoding="utf-8" ?> 
  2. <quartz xmlns="http://quartznet.sourceforge.net/JobSchedulingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" overwrite-existing-jobs="true"> 
  3.   <job> 
  4.     <job-detail> 
  5.       <name>定时更新状态</name> 
  6.       <group>定时更新</group> 
  7.       <description>定时更新产品的状态类型</description> 
  8.       <job-type>MyInfo.InfoBLL,MyInfo</job-type> 
  9.     </job-detail> 
  10.     <trigger> 
  11.       <cron> 
  12.         <name>定时更新状态</name> 
  13.         <group>定时更新</group> 
  14.         <job-name>定时更新</job-name> 
  15.         <job-group>定时更新</job-group> 
  16.         <cron-expression> 0 * 15 * * ? </cron-expression> 
  17.       </cron> 
  18.     </trigger> 
  19.   </job> 
  20. </quartz> 

配置文件说明见下一篇!O(∩_∩)O~

你可能感兴趣的:(quartz)