public class ManInfo { static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(InfoBLL)); public static void Start() { ISchedulerFactory _schedFactory = new StdSchedulerFactory(); logger.Info("开始执行程序"); try { //计划任务 IScheduler sched = _schedFactory.GetScheduler(); JobSchedulingDataProcessor processor = new JobSchedulingDataProcessor(true, true); Stream s = new FileStream(AppDomain.CurrentDomain.BaseDirectory + (@"macher-setting.xml"), FileMode.Open); processor.ProcessStream(s, null); processor.ScheduleJobs(new Hashtable(), sched, false); sched.Start(); } catch (Exception ex) { logger.Error("Application_Start:" + ex); } } }
public class InfoBLL : IJob { static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(InfoBLL)); void IJob.Execute(JobExecutionContext context) { logger.Info("开始更改信息状态"); Import(); logger.Info("开始修复更改出现的信息"); repair(); // System.Threading.WaitCallback waitCallback = new WaitCallback(BindWLT); //ThreadPool.QueueUserWorkItem(waitCallback, arr); //ThreadPool.QueueUserWorkItem(waitCallback, arr1); } }
最重要的要配置:
<?xml version="1.0" encoding="utf-8" ?> <quartz xmlns="http://quartznet.sourceforge.net/JobSchedulingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" overwrite-existing-jobs="true"> <job> <job-detail> <name>定时更新状态</name> <group>定时更新</group> <description>定时更新产品的状态类型</description> <job-type>MyInfo.InfoBLL,MyInfo</job-type> </job-detail> <trigger> <cron> <name>定时更新状态</name> <group>定时更新</group> <job-name>定时更新</job-name> <job-group>定时更新</job-group> <cron-expression> 0 * 15 * * ? </cron-expression> </cron> </trigger> </job> </quartz>