Quartz.NET: http://quartznet.sourceforge.net/ (现为2.2版本)
Sourceforge:http://sourceforge.net/projects/quartznet/files/quartznet (项目打开貌似有点问题)
GitHub:https://github.com/quartznet/quartznet
NuGet : http://nuget.org/packages/Quartz
stackoverflow:http://stackoverflow.com/questions/tagged/quartz.net

相对JAVA版的来说,文档太少了,我找了一个入门文档(QuartzNetQuickstart),基于XML配置的,个人认为配置更灵活,例如我写好一个服务,以后需要加任务,只需要写好实现类,修改下配置就行了。可以在如下地址下载:http://jayvilalta.com/blog/downloads/

在ASP.NET中使用,主要考虑到Application_End等一些列问题,现改用window服务。
http://asdfblog.com/technology/aspnet-scheduled-tasks-with-quartznet.html
http://blog.csdn.net/a497785609/article/details/5941283

Quartz.Net的组成

Common.Logging (一定注意版本2.1.2,或者使用相应的Nuget文件来获取)
C5(一个C#和其他CLI语言的泛型集合类, Net2.0及以上才可以使用,并支持 Mono http://www.itu.dk/research/c5/)
quartz.config(有一个默认配置)

# Default Properties file for use by StdSchedulerFactory
# to create a Quartz Scheduler Instance, if a different
# properties file is not explicitly specified.
#
quartz.scheduler.instanceName = DefaultQuartzScheduler
quartz.threadPool.threadCount = 10
quartz.threadPool.threadPriority = Normal
quartz.jobStore.misfireThreshold = 60000

window服务

  1. public partial class QuatzNTService : ServiceBase
  2. {
  3. private readonly ILog logger;
  4. private IScheduler scheduler;
  5. public QuatzNTService()
  6. {
  7. InitializeComponent();
  8. logger = LogManager.GetLogger(GetType());
  9. ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
  10. scheduler = schedulerFactory.GetScheduler();
  11. }
  12. protected override void OnStart(string[] args)
  13. {
  14. scheduler.Start();
  15. logger.Info("Quartz服务成功启动");
  16. }
  17.  
  18. protected override void OnStop()
  19. {
  20. scheduler.Shutdown(true);
  21. logger.Info("Quartz服务成功终止");
  22. }
  23.  
  24. protected override void OnPause()
  25. {
  26. scheduler.PauseAll();
  27. }
  28.  
  29. protected override void OnContinue()
  30. {
  31. scheduler.ResumeAll();
  32. }
  33. }

任务

  1. /// <summary>
  2. /// This is just a simple job that says "Hello" to the world.
  3. /// </summary>
  4. /// <author>Bill Kratzer</author>
  5. /// <author>Marko Lahma (.NET)</author>
  6. public class HelloJob : IJob
  7. {
  8. private static readonly ILog logger = LogManager.GetLogger(typeof(HelloJob));
  9.  
  10. /// <summary>
  11. /// Called by the <see cref="IScheduler" /> when a <see cref="ITrigger" />
  12. /// fires that is associated with the <see cref="IJob" />.
  13. /// </summary>
  14. /// <remarks>
  15. /// The implementation may wish to set a result object on the
  16. /// JobExecutionContext before this method exits. The result itself
  17. /// is meaningless to Quartz, but may be informative to
  18. /// <see cref="IJobListener" />s or
  19. /// <see cref="ITriggerListener" />s that are watching the job's
  20. /// execution.
  21. /// </remarks>
  22. /// <param name="context">The execution context.</param>
  23. public void Execute(IJobExecutionContext context)
  24. {
  25. logger.Info("HelloJob running...");
  26. Thread.Sleep(TimeSpan.FromSeconds(5));
  27. logger.Info("HelloJob run finished.");
  28. }

log4j

  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <configuration>
  3. <configSections>
  4. <section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  5. <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  6. <sectionGroup name="common">
  7. <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
  8. </sectionGroup>
  9. </configSections>
  10.  
  11. <common>
  12. <logging>
  13. <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4net1211">
  14. <arg key="configType" value="INLINE" />
  15. </factoryAdapter>
  16. </logging>
  17. </common>
  18.  
  19. <log4net>
  20. <!--控制台日志-->
  21. <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
  22. <layout type="log4net.Layout.PatternLayout">
  23. <conversionPattern value="%d [%t] %-5p %l - %m%n" />
  24. </layout>
  25. </appender>
  26. <!--文本信息日志-->
  27. <appender name="InfoFileAppender" type="log4net.Appender.RollingFileAppender">
  28. <file value="log/" />
  29. <appendToFile value="true" />
  30. <param name="DatePattern" value="yyyyMMdd".txt"" />
  31. <rollingStyle value="Date" />
  32. <maxSizeRollBackups value="100" />
  33. <maximumFileSize value="1024KB" />
  34. <staticLogFileName value="false" />
  35. <Encoding value="UTF-8" />
  36. <filter type="log4net.Filter.LevelRangeFilter">
  37. <param name="LevelMin" value="INFO" />
  38. <param name="LevelMax" value="INFO" />
  39. </filter>
  40. <layout type="log4net.Layout.PatternLayout">
  41. <conversionPattern value="%date %-5level %logger - %message%newline" />
  42. </layout>
  43. </appender>
  44. <!--文本错误日志-->
  45. <appender name="ErrorFileAppender" type="log4net.Appender.RollingFileAppender">
  46. <file value="log/error.txt" />
  47. <appendToFile value="true" />
  48. <rollingStyle value="Size" />
  49. <maxSizeRollBackups value="100" />
  50. <maximumFileSize value="10240KB" />
  51. <staticLogFileName value="true" />
  52. <Encoding value="UTF-8" />
  53. <filter type="log4net.Filter.LevelRangeFilter">
  54. <param name="LevelMin" value="WARN" />
  55. <param name="LevelMax" value="FATAL" />
  56. </filter>
  57. <layout type="log4net.Layout.PatternLayout">
  58. <conversionPattern value="%date %-5level %logger - %message%newline" />
  59. </layout>
  60. </appender>
  61. <root>
  62. <level value="INFO" />
  63. <appender-ref ref="ConsoleAppender" />
  64. <appender-ref ref="InfoFileAppender" />
  65. <appender-ref ref="ErrorFileAppender" />
  66. <!-- uncomment to enable event log appending -->
  67. <!-- <appender-ref ref="EventLogAppender" /> -->
  68. </root>
  69. </log4net>
  70.  
  71. <!--
  72. We use quartz.config for this server, you can always use configuration section if you want to.
  73. Configuration section has precedence here.
  74. -->
  75. <!--
  76. <quartz>
  77. <add key="quartz.scheduler.instanceName" value="ExampleDefaultQuartzScheduler"/>
  78.  
  79. <add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz"/>
  80. <add key="quartz.threadPool.threadCount" value="10"/>
  81. <add key="quartz.threadPool.threadPriority" value="2"/>
  82.  
  83. <add key="quartz.jobStore.misfireThreshold" value="60000"/>
  84. <add key="quartz.jobStore.type" value="Quartz.Simpl.RAMJobStore, Quartz"/>
  85. </quartz>
  86. -->
  87. <startup>
  88. <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  89. </startup>
  90. </configuration>

配置

  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <!-- This file contains job definitions in schema version 2.0 format -->
  4.  
  5. <job-scheduling-data xmlns="http://quartznet.sourceforge.net/JobSchedulingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0">
  6.  
  7. <processing-directives>
  8. <!-- 在计划作业和触发器是应遵循的命令和原则 -->
  9. <overwrite-existing-data>true</overwrite-existing-data>
  10. </processing-directives>
  11.  
  12. <schedule>
  13. <job>
  14. <name>HelloJob</name>
  15. <group>HelloJobGroup</group>
  16. <description>Hello job for Quartz</description>
  17. <job-type>Quartz.Example.HelloJob, Quartz.Example</job-type>
  18. <durable>true</durable>
  19. <recover>false</recover>
  20. </job>
  21. <trigger>
  22. <cron>
  23. <name>HelloTrigger</name>
  24. <group>HelloTriggerGroup</group>
  25. <description>Simple trigger to simply fire sample job</description>
  26. <job-name>HelloJob</job-name>
  27. <job-group>HelloJobGroup</job-group>
  28. <!--每10秒中执行一次-->
  29. <cron-expression>0/10 * * * * ?</cron-expression>
  30. </cron>
  31. </trigger>
  32.  
  33. <!--
  34. <trigger>
  35. <simple>
  36. <name>HelloTrigger</name>
  37. <group>HelloTriggerGroup</group>
  38. <description>Simple trigger to simply fire Hello job</description>
  39. <job-name>HelloJob</job-name>
  40. <job-group>HelloJobGroup</job-group>
  41. <misfire-instruction>SmartPolicy</misfire-instruction>
  42. <repeat-count>-1</repeat-count>
  43. <repeat-interval>10000</repeat-interval>
  44. </simple>
  45. </trigger>
  46. -->
  47. </schedule>
  48. </job-scheduling-data>

安装服务 C:\Windows\Microsoft.NET\Framework64\v4.0.30319  InstallUtil C:\IIS\QuatzServiceQuatz.Service.exe
卸载服务 C:\Windows\Microsoft.NET\Framework64\v4.0.30319  InstallUtil /u C:\IIS\QuatzServiceQuatz.Service.exe

日志

  1. 2013-11-16 19:04:42,219 INFO Quartz.Impl.StdSchedulerFactory - Using default implementation for object serializer
  2. 2013-11-16 19:04:42,246 INFO Quartz.Impl.StdSchedulerFactory - Using default implementation for ThreadExecutor
  3. 2013-11-16 19:04:42,261 INFO Quartz.Core.SchedulerSignalerImpl - Initialized Scheduler Signaller of type: Quartz.Core.SchedulerSignalerImpl
  4. 2013-11-16 19:04:42,262 INFO Quartz.Core.QuartzScheduler - Quartz Scheduler v.2.2.400.0 created.
  5. 2013-11-16 19:04:42,268 INFO Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin - Registering Quartz Job Initialization Plug-in.
  6. 2013-11-16 19:04:42,270 INFO Quartz.Simpl.RAMJobStore - RAMJobStore initialized.
  7. 2013-11-16 19:04:42,284 INFO Quartz.Simpl.RemotingSchedulerExporter - Remoting is allowing remote calls
  8. 2013-11-16 19:04:42,285 INFO Quartz.Simpl.RemotingSchedulerExporter - Registering remoting channel of type 'System.Runtime.Remoting.Channels.Tcp.TcpChannel' to port (555) with name (httpQuartz)
  9. 2013-11-16 19:04:42,286 INFO Quartz.Simpl.RemotingSchedulerExporter - Remoting channel registered successfully
  10. 2013-11-16 19:04:42,287 INFO Quartz.Simpl.RemotingSchedulerExporter - Successfully marhalled remotable scheduler under name 'QuartzScheduler'
  11. 2013-11-16 19:04:42,290 INFO Quartz.Core.QuartzScheduler - Scheduler meta-data: Quartz Scheduler (v2.2.400.0) 'ServerScheduler' with instanceId 'NON_CLUSTERED'
  12. Scheduler class: 'Quartz.Core.QuartzScheduler' - access via remote incovation.
  13. NOT STARTED.
  14. Currently in standby mode.
  15. Number of jobs executed: 0
  16. Using thread pool 'Quartz.Simpl.SimpleThreadPool' - with 10 threads.
  17. Using job-store 'Quartz.Simpl.RAMJobStore' - which does not support persistence. and is not clustered.
  18.  
  19. 2013-11-16 19:04:42,291 INFO Quartz.Impl.StdSchedulerFactory - Quartz scheduler 'ServerScheduler' initialized
  20. 2013-11-16 19:04:42,291 INFO Quartz.Impl.StdSchedulerFactory - Quartz scheduler version: 2.2.400.0
  21. 2013-11-16 19:04:42,301 INFO Quartz.Xml.XMLSchedulingDataProcessor - Parsing XML file: C:\IIS\QuatzService\quartz_jobs.xml with systemId: ~/quartz_jobs.xml
  22. 2013-11-16 19:04:42,492 INFO Quartz.Xml.XMLSchedulingDataProcessor - Adding 1 jobs, 1 triggers.
  23. 2013-11-16 19:04:42,496 INFO Quartz.Xml.XMLSchedulingDataProcessor - Adding job: HelloJobGroup.HelloJob
  24. 2013-11-16 19:04:42,534 INFO Quartz.Core.QuartzScheduler - Scheduler ServerScheduler_$_NON_CLUSTERED started.
  25. 2013-11-16 19:04:42,535 INFO Quatz.Service.QuatzNTService - Quartz服务成功启动
  26. 2013-11-16 19:04:50,019 INFO Quartz.Example.HelloJob - HelloJob running...
  27. 2013-11-16 19:04:55,021 INFO Quartz.Example.HelloJob - HelloJob run finished.
  28. 2013-11-16 19:05:00,001 INFO Quartz.Example.HelloJob - HelloJob running...
  29. 2013-11-16 19:05:05,002 INFO Quartz.Example.HelloJob - HelloJob run finished.
  30. 2013-11-16 19:05:10,000 INFO Quartz.Example.HelloJob - HelloJob running...
  31. 2013-11-16 19:05:15,000 INFO Quartz.Example.HelloJob - HelloJob run finished.
  32. 2013-11-16 19:05:19,999 INFO Quartz.Example.HelloJob - HelloJob running...
  33. 2013-11-16 19:05:25,000 INFO Quartz.Example.HelloJob - HelloJob run finished.
  34. 2013-11-16 19:05:30,000 INFO Quartz.Example.HelloJob - HelloJob running...
  35. 2013-11-16 19:05:35,000 INFO Quartz.Example.HelloJob - HelloJob run finished.
  36. 2013-11-16 19:05:40,000 INFO Quartz.Example.HelloJob - HelloJob running...
  37. 2013-11-16 19:05:45,000 INFO Quartz.Example.HelloJob - HelloJob run finished.
  38. 2013-11-16 19:05:49,999 INFO Quartz.Example.HelloJob - HelloJob running...
  39. 2013-11-16 19:05:54,999 INFO Quartz.Example.HelloJob - HelloJob run finished.
  40. 2013-11-16 19:06:00,000 INFO Quartz.Example.HelloJob - HelloJob running...
  41. 2013-11-16 19:06:05,000 INFO Quartz.Example.HelloJob - HelloJob run finished.
  42. 2013-11-16 19:06:10,004 INFO Quartz.Example.HelloJob - HelloJob running...
  43. 2013-11-16 19:06:15,005 INFO Quartz.Example.HelloJob - HelloJob run finished.
  44. 2013-11-16 19:06:20,000 INFO Quartz.Example.HelloJob - HelloJob running...
  45. 2013-11-16 19:06:25,000 INFO Quartz.Example.HelloJob - HelloJob run finish

Window服务与Quartz.NET的更多相关文章

  1. Window服务基于Quartz.Net组件实现定时任务调度(二)

    前言: 在上一章中,我们通过利用控制台实现定时任务调度,已经大致了解了如何基于Quartz.Net组件实现任务,至少包括三部分:job(作业),trigger(触发器),scheduler(调度器). ...

  2. CrystalQuartz实现Quartz的window服务的远程管理

    1. 建一个空的ASP.NET WebSite,利用NuGet安装CrystalQuartz.Remote 包 我们可以看到,配置文件中多了如下节点: <crystalQuartz> &l ...

  3. Window服务项目脚手架

    本人最近工作用到window服务程序,于是尝试分享下经验,开源了一个window服务脚手架项目,把window服务程序必不可少的组件集成进去,如日志组件log4net,window服务挂在后台,用日志 ...

  4. C#编写window服务,一步一步(1)

    Window服务是啥,这里就不废话了,如何用在哪里用也不废话了,这里我这篇文章只是详述了我在vs2012中创建window服务的经过,希望对你有所帮助. 另外:我在编写服务过程中参考了 Profess ...

  5. WPF Window 服务安装

    一.安装服务 1.已管理员的身份启动CMD 2.输入 cd C:\Windows\Microsoft.NET\Framework\v4.0.30319 回车 3.输入 InstallUtil.exe ...

  6. Windows服务调用Quartz.net 实现消息调度

    Quartz.NET是一个开源的作业调度框架,是OpenSymphony 的 Quartz API的.NET移植,它用C#写成,可用于winform和asp.net应用中.它提供了巨大的灵活性而不牺牲 ...

  7. Window服务初级教程以及log4net配置文件初始化

    Window服务初级教程:http://www.jb51.net/article/48987.htm 另外,配置log4net这个日志功能的时候需要初始化,不然会报没有初始化的错误,而且初始化的节点应 ...

  8. C# 编写Window服务基础(一)

    一.Windows服务介绍: Windows服务以前被称作NT服务,是一些运行在Windows NT.Windows 2000和Windows XP等操作系统下用户环境以外的程序.在以前,编写Wind ...

  9. C# 编写短信发送Window服务

    我们做项目过程中,一般都会有发送短信的需求.最常见的就是户注册或者登录时发送短信验证码.不同类型的短信发送,我们都可以放到到一张短信表中,然后通过一个定时的作业去执行短信发送.而定时作业的执行,我们就 ...

随机推荐

  1. 20169207《linux内核原理与分析》第二周作业

    第一部分:学习MOOC网Linux内核分析的课程. 首先对冯诺依曼体系结构和存储程序计算机工作模型进行了了解,查阅资料,对冯诺依曼体系的特点与课堂上的相结合,真实明白了模型的特点. 在汇编C语言程序时 ...

  2. pycharm的注册码,所有版本

    77751S0VBA-eyJsaWNlbnNlSWQiOiI3Nzc1MVMwVkJBIiwibGljZW5zZWVOYW1lIjoi5b285bK4IHNvZnR3YXJlMiIsImFzc2lnb ...

  3. int与String互转

    1.把String转化为int类型 Integer.valueOf(i); 2.把int转化为String 1)String.valueOf(i) 2)Integer.toString(i) 3)i+ ...

  4. 最小生成树Prim poj1258 poj2485 poj1789

    poj:1258 Agri-Net Time Limit: 1000 MS Memory Limit: 10000 KB 64-bit integer IO format: %I64d , %I64u ...

  5. 4.css基础

    1 Css概念 CSS 指层叠样式表 (Cascading Style Sheets)(级联样式表) Css是用来美化html标签的,相当于页面化妆. ◆样式表书写位置 2选择器 2.1 写法 选择器 ...

  6. iOS开发 关于iBeacon的一些记录

    最近时间一直在研究ibeacon所以把自己遇到的一些问题写下来做个笔记. 参考资料:https://github.com/nixzhu/dev-blog/blob/master/2014-04-23- ...

  7. 加密算法(DES,AES,RSA,MD5,SHA1,Base64)比较和项目应用(转载)

    加密技术通常分为两大类:"对称式"和"非对称式". 对称性加密算法:对称式加密就是加密和解密使用同一个密钥.信息接收双方都需事先知道密匙和加解密算法且其密匙是相 ...

  8. Excel 两列单元格合并超级链接的VBA 写法

    Excel 单元格 分两列 (B列存放姓名, C列存放链接) 列如: 姓名 学号 博客地址 1309032022 李汉超 http://www.cnblogs.com/Vpygamalion/ 141 ...

  9. 完美融合 nextjs 和 antd

    相信大家在使用nextjs的时候,难免遇到一些坑.其实可能大部分原因在于 nextjs 做了很多封装,我们可能不能第一时间搞清楚包括它相关的所有配置,比如其中的webpack配置.我前面也写过 SSR ...

  10. 源自KPI交谈的思考

    说明白一件事情不容易 前言 跟领导谈及下半年KPI的时候,问我什么打算/计划,在交谈过程中,有几个有意思的点 问题 Q: 目标是hold住服务端,那么怎么样才算hold住服务端? Q: 如何推动别人去 ...