(1)在web.config中进行相关配置

<configSections> <section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"/> <sectionGroup name="common"> <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging"/> </sectionGroup> </configSections>

<common> <logging> <factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging"> <arg key="showLogName" value="true"/> <arg key="showDataTime" value="true"/> <arg key="level" value="DEBUG"/> <arg key="dateTimeFormat" value="HH:mm:ss:fff"/> </factoryAdapter> </logging> </common> <quartz> <add key="quartz.scheduler.instanceName" value="ExampleDefaultQuartzScheduler"/> <add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz"/> <add key="quartz.threadPool.threadCount" value="10"/> <add key="quartz.threadPool.threadPriority" value="2"/> <add key="quartz.jobStore.misfireThreshold" value="60000"/> <add key="quartz.jobStore.type" value="Quartz.Simpl.RAMJobStore, Quartz"/> </quartz>

(2)创建一个普通类,实现Quartz.IJob接口

public class MyJog: IJob { public MyJog() {  }

public void Execute(JobExecutionContext context) { //throw new Exception("The method or operation is not implemented."); //你的处理逻辑,也就是“工作” } }

接口非常简单,只要在Execute()方法中进行逻辑处理就可以了。比如,读取数据库数据,或者是读取电子邮件。

(3)在Global.asax文件中启动工作调度 这便于我们在web应用启动时,就启动工作调度。

<%@ Import Namespace="Quartz" %>

<script runat="server">

IScheduler sched; void Application_Start(object sender, EventArgs e) { // 在应用程序启动时运行的代码 ISchedulerFactory sf = new Quartz.Impl.StdSchedulerFactory(); sched = sf.GetScheduler(); JobDetail job = new JobDetail("job1", "group1", typeof(MyJob));

string cronExpr = "0 0 1 * * ?";

CronTrigger trigger = new CronTrigger("trigger1", "group1", "job1", "group1",cronExpr); sched.AddJob(job, true); DateTime ft = sched.ScheduleJob(trigger); sched.Start(); } void Application_End(object sender, EventArgs e) { // 在应用程序关闭时运行的代码 if (sched != null) { sched.Shutdown(true); } }

</script>

需要注意的是,当Application_End的时候,需要关闭Quartz的工作。

最后 代码部分完毕之后,要重启WWW服务,并且访问站点内任一ASPX页面,任务方可执行!

最新文章

  1. maven 记录
  2. 轻松创建R语言函数包
  3. 七个结构模式之适配器模式(Adapter Pattern)
  4. 浅谈Java五大设计原则之代理模式
  5. HDU 4388 To the moon
  6. Events in ASP.NET Master and Content Pages
  7. 安装webmin
  8. 【转】开发者教程:如何将Android应用发布到Google Play(Android Market)官方市场
  9. go程序性能优化
  10. 树型动态规划(树形dp)
  11. Python登录页面及
  12. JS语句
  13. [BBS]搭建开源论坛之Jforum搭配开源CKEDITOR
  14. 1034. Head of a Gang (30) -string离散化 -map应用 -并查集
  15. Android 音视频深入 二十 FFmpeg视频压缩(附源码下载)
  16. ECDSA数字签名算法
  17. JS时间戳转换成时间格式
  18. bzoj千题计划311:bzoj5017: [Snoi2017]炸弹(线段树优化tarjan构图)
  19. foreach退出循环(新人请多多关照~)
  20. bzoj4361 isn (dp+树状数组+容斥)

热门文章

  1. Project Euler Problem3
  2. 【前端vue开发】vue开发总结
  3. css-position属性实例1
  4. maven dependencies 报错
  5. Heist
  6. java PriorityQueue(优先级队列)
  7. Laravel Model 的 fillable (白名单)与 guarded (黑名单)
  8. opencv的级联分类器(mac)
  9. Vue学习系列---安装
  10. Eclipse导入Android项目的方法(转)