1. 引用quartz.dll和Common.Logging.dll
2. Web.Config中<configSections>节点下加入
<section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.2.3,Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
3. <appSettings>节点中加入
<add key="rbac_cronExpr" value="0 0/1 * * * ?"/> 注:每1分钟循环一次
4. configuration节点下加入
1 <quartz> 2 <add key="quartz.scheduler.instanceName" value="ExampleDefaultQuartzScheduler"/> 3 <add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz"/> 4 <add key="quartz.threadPool.threadCount" value="1"/> 5 <add key="quartz.threadPool.threadPriority" value="2"/> 6 <add key="quartz.jobStore.misfireThreshold" value="60000"/> 7 <add key="quartz.jobStore.type" value="Quartz.Simpl.RAMJobStore, Quartz"/> 8 </quartz>
5. 全局Global.asax文件中加入
1 private IScheduler rbac_sched; 2 protected void Application_Start(object sender, EventArgs e) 3 { 4 5 ISchedulerFactory RBACExport_Job = new Quartz.Impl.StdSchedulerFactory(); 6 rbac_sched = RBACExport_Job.GetScheduler(); 7 //Type t = Type.GetType("Sample2.App_Code.TestQuartzJob"); 8 JobDetail rbac_job = new JobDetail("rbac_job", "rbac_group", typeof(Sample2.App_Code.TestQuartzJob)); 9 string rbac_cronExpr = ConfigurationManager.AppSettings["rbac_cronExpr"]; 10 CronTrigger rbac_trigger = new CronTrigger("rbac_trigger", "rbac_group", "rbac_job", "rbac_group", rbac_cronExpr); 11 rbac_sched.AddJob(rbac_job, true); 12 DateTime rbac_ft = rbac_sched.ScheduleJob(rbac_trigger); 13 rbac_sched.Start(); 14 } 15 16 protected void Application_End(object sender, EventArgs e) 17 { 18 //在应用程序关闭时运行的代码 19 if (rbac_sched != null) 20 { 21 rbac_sched.Shutdown(true); 22 } 23 } 24