标签:des style blog http java color
使用普通Windows服务创建Quartz.Net服务项目
C5.dll 一个C#和其他CLI语言的泛型集合类。.Net2.0及以上才可以使用。简介地址:http://www.itu.dk/research/c5/ Common.Logging.dll 通用日志接口 Common.Logging.Log4Net.dll 提供log4net对通用日志接口(Common.Logging)的实现 log4net.dll 小白都知道不解释
至此Quarzt.Net 的Windows服务已成功创建,接下创建实现了IJob接口Quartz任务
using System;
namespace Quartz.Net.Demo
{
/// <summary>
/// 实现IJob接口
/// </summary>
public class DemoJob1 : IJob
{
//使用Common.Logging.dll日志接口实现日志记录
private static readonly Common.Logging.ILog logger = Common.Logging.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#region IJob 成员
public void Execute(IJobExecutionContext context)
{
try
{
logger.Info("DemoJob1 任务开始运行");
for (int i = 0; i < 10; i++)
{
logger.InfoFormat("DemoJob1 正在运行{0}", i);
}
logger.Info("DemoJob1任务运行结束");
}
catch (Exception ex)
{
logger.Error("DemoJob2 运行异常", ex);
}
}
#endregion
}
}
using System;
namespace Quartz.Net.Demo
{
/// <summary>
/// 实现IJob接口
/// </summary>
public class DemoJob2 : IJob
{
//使用log4net.dll日志接口实现日志记录
private static readonly log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#region IJob 成员
public void Execute(IJobExecutionContext context)
{
try
{
logger.Info("DemoJob2 任务开始运行");
for (int i = 0; i < 10; i++)
{
logger.InfoFormat("DemoJob2 正在运行{0}", i);
}
logger.Info("DemoJob2任务运行结束");
}
catch (Exception ex)
{
logger.Error("DemoJob2 运行异常", ex);
}
}
#endregion
}
}
<?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>
<!--定义示例任务1 Job-->
<job>
<name>DemoJob1</name>
<group>DeomJobGroup</group>
<description>Quartz.Net示例任务1</description>
<job-type>Quartz.Net.Demo.DemoJob1,Quartz.Net.Demo</job-type>
<durable>true</durable>
<recover>false</recover>
</job>
<!--定义示例任务2 Job-->
<job>
<name>DemoJob2</name>
<group>DeomJobGroup</group>
<description>Quartz.Net示例任务2</description>
<job-type>Quartz.Net.Demo.DemoJob2,Quartz.Net.Demo</job-type>
<durable>true</durable>
<recover>false</recover>
</job>
<!--定义示例任务1 触发器 每30秒执行一次DemoJob1任务-->
<trigger>
<cron>
<name>DemoJob1Trigger</name>
<group>DeomJobTriggerGroup</group>
<job-name>DemoJob1</job-name>
<job-group>DeomJobGroup</job-group>
<cron-expression>0/30 * * * * ?</cron-expression>
</cron>
</trigger>
<!--定义示例任务2 触发器 每分钟执行一次DemoJob2任务-->
<trigger>
<cron>
<name>DemoJob2Trigger1</name>
<group>DeomJobTriggerGroup</group>
<job-name>DemoJob2</job-name>
<job-group>DeomJobGroup</job-group>
<cron-expression>0 * * * * ?</cron-expression>
</cron>
</trigger>
<!--定义示例任务2 触发器 每天凌晨01:00执行一次DemoJob2任务-->
<trigger>
<cron>
<name>DemoJob2Trigger2</name>
<group>DeomJobTriggerGroup</group>
<job-name>DemoJob2</job-name>
<job-group>DeomJobGroup</job-group>
<cron-expression