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服务

public partial class QuatzNTService : ServiceBase
{
private readonly ILog logger;
private IScheduler scheduler;
public QuatzNTService()
{
InitializeComponent();
logger = LogManager.GetLogger(GetType());
ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
scheduler = schedulerFactory.GetScheduler();
}
protected override void OnStart(string[] args)
{
scheduler.Start();
logger.Info("Quartz服务成功启动");
} protected override void OnStop()
{
scheduler.Shutdown(true);
logger.Info("Quartz服务成功终止");
} protected override void OnPause()
{
scheduler.PauseAll();
} protected override void OnContinue()
{
scheduler.ResumeAll();
}
}

任务

 /// <summary>
/// This is just a simple job that says "Hello" to the world.
/// </summary>
/// <author>Bill Kratzer</author>
/// <author>Marko Lahma (.NET)</author>
public class HelloJob : IJob
{
private static readonly ILog logger = LogManager.GetLogger(typeof(HelloJob)); /// <summary>
/// Called by the <see cref="IScheduler" /> when a <see cref="ITrigger" />
/// fires that is associated with the <see cref="IJob" />.
/// </summary>
/// <remarks>
/// The implementation may wish to set a result object on the
/// JobExecutionContext before this method exits. The result itself
/// is meaningless to Quartz, but may be informative to
/// <see cref="IJobListener" />s or
/// <see cref="ITriggerListener" />s that are watching the job's
/// execution.
/// </remarks>
/// <param name="context">The execution context.</param>
public void Execute(IJobExecutionContext context)
{
logger.Info("HelloJob running...");
Thread.Sleep(TimeSpan.FromSeconds(5));
logger.Info("HelloJob run finished.");
}

log4j

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections> <common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4net1211">
<arg key="configType" value="INLINE" />
</factoryAdapter>
</logging>
</common> <log4net>
<!--控制台日志-->
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d [%t] %-5p %l - %m%n" />
</layout>
</appender>
<!--文本信息日志-->
<appender name="InfoFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="log/" />
<appendToFile value="true" />
<param name="DatePattern" value="yyyyMMdd".txt"" />
<rollingStyle value="Date" />
<maxSizeRollBackups value="100" />
<maximumFileSize value="1024KB" />
<staticLogFileName value="false" />
<Encoding value="UTF-8" />
<filter type="log4net.Filter.LevelRangeFilter">
<param name="LevelMin" value="INFO" />
<param name="LevelMax" value="INFO" />
</filter>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %-5level %logger - %message%newline" />
</layout>
</appender>
<!--文本错误日志-->
<appender name="ErrorFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="log/error.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="100" />
<maximumFileSize value="10240KB" />
<staticLogFileName value="true" />
<Encoding value="UTF-8" />
<filter type="log4net.Filter.LevelRangeFilter">
<param name="LevelMin" value="WARN" />
<param name="LevelMax" value="FATAL" />
</filter>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %-5level %logger - %message%newline" />
</layout>
</appender>
<root>
<level value="INFO" />
<appender-ref ref="ConsoleAppender" />
<appender-ref ref="InfoFileAppender" />
<appender-ref ref="ErrorFileAppender" />
<!-- uncomment to enable event log appending -->
<!-- <appender-ref ref="EventLogAppender" /> -->
</root>
</log4net> <!--
We use quartz.config for this server, you can always use configuration section if you want to.
Configuration section has precedence here.
-->
<!--
<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>
-->
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>

配置

<?xml version="1.0" encoding="UTF-8"?>

<!-- This file contains job definitions in schema version 2.0 format -->

<job-scheduling-data xmlns="http://quartznet.sourceforge.net/JobSchedulingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0">

  <processing-directives>
<!-- 在计划作业和触发器是应遵循的命令和原则 -->
<overwrite-existing-data>true</overwrite-existing-data>
</processing-directives> <schedule>
<job>
<name>HelloJob</name>
<group>HelloJobGroup</group>
<description>Hello job for Quartz</description>
<job-type>Quartz.Example.HelloJob, Quartz.Example</job-type>
<durable>true</durable>
<recover>false</recover>
</job>
<trigger>
<cron>
<name>HelloTrigger</name>
<group>HelloTriggerGroup</group>
<description>Simple trigger to simply fire sample job</description>
<job-name>HelloJob</job-name>
<job-group>HelloJobGroup</job-group>
<!--每10秒中执行一次-->
<cron-expression>0/10 * * * * ?</cron-expression>
</cron>
</trigger> <!--
<trigger>
<simple>
<name>HelloTrigger</name>
<group>HelloTriggerGroup</group>
<description>Simple trigger to simply fire Hello job</description>
<job-name>HelloJob</job-name>
<job-group>HelloJobGroup</job-group>
<misfire-instruction>SmartPolicy</misfire-instruction>
<repeat-count>-1</repeat-count>
<repeat-interval>10000</repeat-interval>
</simple>
</trigger>
-->
</schedule>
</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

日志

2013-11-16 19:04:42,219 INFO  Quartz.Impl.StdSchedulerFactory  - Using default implementation for object serializer
2013-11-16 19:04:42,246 INFO Quartz.Impl.StdSchedulerFactory - Using default implementation for ThreadExecutor
2013-11-16 19:04:42,261 INFO Quartz.Core.SchedulerSignalerImpl - Initialized Scheduler Signaller of type: Quartz.Core.SchedulerSignalerImpl
2013-11-16 19:04:42,262 INFO Quartz.Core.QuartzScheduler - Quartz Scheduler v.2.2.400.0 created.
2013-11-16 19:04:42,268 INFO Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin - Registering Quartz Job Initialization Plug-in.
2013-11-16 19:04:42,270 INFO Quartz.Simpl.RAMJobStore - RAMJobStore initialized.
2013-11-16 19:04:42,284 INFO Quartz.Simpl.RemotingSchedulerExporter - Remoting is allowing remote calls
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)
2013-11-16 19:04:42,286 INFO Quartz.Simpl.RemotingSchedulerExporter - Remoting channel registered successfully
2013-11-16 19:04:42,287 INFO Quartz.Simpl.RemotingSchedulerExporter - Successfully marhalled remotable scheduler under name 'QuartzScheduler'
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'
Scheduler class: 'Quartz.Core.QuartzScheduler' - access via remote incovation.
NOT STARTED.
Currently in standby mode.
Number of jobs executed: 0
Using thread pool 'Quartz.Simpl.SimpleThreadPool' - with 10 threads.
Using job-store 'Quartz.Simpl.RAMJobStore' - which does not support persistence. and is not clustered. 2013-11-16 19:04:42,291 INFO Quartz.Impl.StdSchedulerFactory - Quartz scheduler 'ServerScheduler' initialized
2013-11-16 19:04:42,291 INFO Quartz.Impl.StdSchedulerFactory - Quartz scheduler version: 2.2.400.0
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
2013-11-16 19:04:42,492 INFO Quartz.Xml.XMLSchedulingDataProcessor - Adding 1 jobs, 1 triggers.
2013-11-16 19:04:42,496 INFO Quartz.Xml.XMLSchedulingDataProcessor - Adding job: HelloJobGroup.HelloJob
2013-11-16 19:04:42,534 INFO Quartz.Core.QuartzScheduler - Scheduler ServerScheduler_$_NON_CLUSTERED started.
2013-11-16 19:04:42,535 INFO Quatz.Service.QuatzNTService - Quartz服务成功启动
2013-11-16 19:04:50,019 INFO Quartz.Example.HelloJob - HelloJob running...
2013-11-16 19:04:55,021 INFO Quartz.Example.HelloJob - HelloJob run finished.
2013-11-16 19:05:00,001 INFO Quartz.Example.HelloJob - HelloJob running...
2013-11-16 19:05:05,002 INFO Quartz.Example.HelloJob - HelloJob run finished.
2013-11-16 19:05:10,000 INFO Quartz.Example.HelloJob - HelloJob running...
2013-11-16 19:05:15,000 INFO Quartz.Example.HelloJob - HelloJob run finished.
2013-11-16 19:05:19,999 INFO Quartz.Example.HelloJob - HelloJob running...
2013-11-16 19:05:25,000 INFO Quartz.Example.HelloJob - HelloJob run finished.
2013-11-16 19:05:30,000 INFO Quartz.Example.HelloJob - HelloJob running...
2013-11-16 19:05:35,000 INFO Quartz.Example.HelloJob - HelloJob run finished.
2013-11-16 19:05:40,000 INFO Quartz.Example.HelloJob - HelloJob running...
2013-11-16 19:05:45,000 INFO Quartz.Example.HelloJob - HelloJob run finished.
2013-11-16 19:05:49,999 INFO Quartz.Example.HelloJob - HelloJob running...
2013-11-16 19:05:54,999 INFO Quartz.Example.HelloJob - HelloJob run finished.
2013-11-16 19:06:00,000 INFO Quartz.Example.HelloJob - HelloJob running...
2013-11-16 19:06:05,000 INFO Quartz.Example.HelloJob - HelloJob run finished.
2013-11-16 19:06:10,004 INFO Quartz.Example.HelloJob - HelloJob running...
2013-11-16 19:06:15,005 INFO Quartz.Example.HelloJob - HelloJob run finished.
2013-11-16 19:06:20,000 INFO Quartz.Example.HelloJob - HelloJob running...
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. RAW转换成RGB

    clc; clear; close all; [filename,pathname]=uigetfile({'*.*','All Files (*.*)'},'Pick a file'); file ...

  2. Attach()和Detach()函数

    一.Windows对象和MFC对象的区别? MFC对象实际上并没有把整个Windows对象都包装在其中.对于窗口:MFC对象它只是有一个窗口句柄而已,这个窗口句柄如果指向一个实际存在的窗口对象(窗口对 ...

  3. c语言:简单排序:冒泡排序法、选择排序法、插入排序法(待写)

    1.冒泡排序法: 假设有n个数需要按从小到大排序,冒泡排序的原理是,在这一排数字中,将第一个数与第二个数比较大小,如果后面的比前面的小,就将他们交换位置.然后再比较第二个和第三个,再交换,直到第n-1 ...

  4. sys/time.h 和 time.h

    今天在燕麦工作第二天.看荣哥给我的程序,发现程序里面用的延时跟我以前使用的不同.导入两个头文件,然后用函数来获得时间.关于这个函数特别查来一下. time.h  是ISO C99 标准日期头文件. s ...

  5. SSM_CRUD新手练习(3)创建数据库

    在上一节我们已经完成了基本的SSM配置,现在需要创建我们数据库. 我们需要两张表分别为tbl_emp(员工表)和tbl_dedpt(部门表).同时d_id是部门表对应dept_id的外键. 需要注意的 ...

  6. Swift可向上滑移出界面的欢迎页简单封装

    使用: -(WelcomView*)welcomeView{ if (!_welcomeView) { _welcomeView = [[NSBundle mainBundle] loadNibNam ...

  7. find的用法(完整)

    一.根据文件或者正则表达式进行匹配 1.列出当前目录(/.code)及子目录下所有文件和文件夹 find . 2.在当前目录(/.code)下查找以.pdf结尾的文件名 find .  -name & ...

  8. 9.js入门

    1.Js介绍 ◆js是一款运行在客户端的网页编程语言. ◆组成部分 ★ecmascript js标准 ★dom 通过js操作网页元素 ★bom 通过api操作浏览器 ◆特点 ★简单易用 ★解释执行 ★ ...

  9. Web应用安全之点击劫持(CLICKJACKING)与X-FRAME-OPTIONS HEADER

    点击劫持(clickjacking)与X-Frame-Options Header 文/玄魂 目录 前言... 1.1 点击劫持(clickjacking attacks)... 1.2  Frame ...

  10. Grid++Report报表工具C/S实战篇(五)

    一.课程介绍 本次分享课程属于<C#高级编程实战技能开发宝典课程系列>中的第五部分,阿笨后续会计划将实际项目中的一些比较实用的关于C#高级编程的技巧分享出来给大家进行学习,不断的收集.整理 ...