Quartz.Net使用经验总结:

学习参考的例子不错,分享一下:

(1)https://www.cnblogs.com/jys509/p/4628926.html,该博文介绍比较全面

(2)https://www.cnblogs.com/abeam/p/8042531.html 该博文有关于任务调度及配置文件详细解释,很棒。

(3)https://www.cnblogs.com/JentZhang/p/9597597.html 不错的学习例子

(4)https://www.cnblogs.com/abeam/p/8042531.html :关于"使用 Topshelf 结合 Quartz.NET 创建 Windows 服务"的总结

(5) https://www.jianshu.com/p/f5118bd69d34 :关于Quartz 2.x 与3.x版本差异分析不错

第一步:新建控制台应用程序:QuartzJobDemo

先直接看目录结构:

第二步直接上源码:
1.作业调度:ServiceRunner.cs源码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using Common.Logging;//引用下面的吧
using log4net;//_logger.InfoFormat("TestJob测试"); ---》为了输出,引用这个吧
using Quartz;
using Quartz.Impl;
using Topshelf; namespace QuartzJobDemo.Services
{
public sealed class ServiceRunner: ServiceControl,ServiceSuspend
{
private readonly IScheduler _scheduler;
private readonly ILog _logger = LogManager.GetLogger(typeof(TestJob)); #region Quartz 2.X版本
public ServiceRunner()
{
_scheduler = StdSchedulerFactory.GetDefaultScheduler();
}
#endregion #region Quartz 3.X版本
//public ServiceRunner()
//{
// scheduler = StdSchedulerFactory.GetDefaultScheduler().GetAwaiter().GetResult();
//}
#endregion public bool Start(HostControl hostControl)
{
_logger.InfoFormat(@"开始服务:{0}", DateTime.Now);
_scheduler.Start();
return true;
} public bool Stop(HostControl hostControl)
{
_logger.InfoFormat(@"停止服务:{0}", DateTime.Now);
_scheduler.Shutdown(false);
return true;
} public bool Continue(HostControl hostControl)
{
_logger.InfoFormat(@"继续服务:{0}", DateTime.Now);
_scheduler.ResumeAll();
return true;
} public bool Pause(HostControl hostControl)
{
_logger.InfoFormat(@"暂停服务:{0}", DateTime.Now);
_scheduler.PauseAll();
return true;
}
}
}
2.作业执行TestJob.cs源码 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using Common.Logging;//引用下面的吧
using log4net;//_logger.InfoFormat("TestJob测试"); ---》为了输出,引用这个吧
using Quartz; namespace QuartzJobDemo
{
public sealed class TestJob: IJob
{
private readonly ILog _logger = LogManager.GetLogger(typeof(TestJob)); #region Quartz 2.X版本
public void Execute(IJobExecutionContext context)
{
_logger.InfoFormat("TestJob测试");
}
#endregion #region Quartz 3.X版本
//public Task Execute(IJobExecutionContext context)
//{
// _logger.InfoFormat("TestJob测试");
// return Task.FromResult(true);
//} /**
* 重点问题是新的IJob实现Execute返回的是Task,老的是void,很多在使用的时候对于这个地方的返回不知道如何处理,看代码增加一行:
return Task.FromResult(true);
*/
#endregion }
} 3.主程序Program.cs源码: using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using QuartzJobDemo.Services;
using Topshelf; namespace QuartzJobDemo
{
/**
* 说明:学习地址:https://www.cnblogs.com/jys509/p/4628926.html
*注意点 (1)
* Quartz版本:2.6.1
* TopShelf版本:3.0.2 TopShelf版本与 Topshelf.Log4Net版本最好一一对应!!!!!
* Topshelf.Log4Net版本:3.0.2
*注意点 (2)
*三个配置文件的属性都是改为始终复制:quartz_jobs.xml log4net.config quartz.config
* 关于配置文件的具体说明:https://www.cnblogs.com/abeam/p/8044460.html
* 注意点(3)
* TestJob.cs中还是引用: using log4net;不要引用using Common.Logging;
*
*这个学习地址: https://www.cnblogs.com/abeam/p/8042531.html 也可以看看!!!+
*/
class Program
{
static void Main(string[] args)
{
log4net.Config.XmlConfigurator.ConfigureAndWatch(
new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "log4net.config"));
HostFactory.Run(x =>
{
#region Quartz 2.X版本: 2.6.1
x.UseLog4Net(); x.Service<ServiceRunner>(); x.SetDescription("QuartzJobDemo服务描述");
x.SetDisplayName("QuartzJobDemo服务显示名称");
x.SetServiceName("QuartzJobDemo服务名称"); x.EnablePauseAndContinue();
#endregion #region Quartz 2.X版本: 2.6.1
//x.UseLog4Net(); //x.Service<ServiceRunner>(s => {
// s.ConstructUsing(name => new ServiceRunner());
// s.WhenStarted((tc, hc) => tc.Start(hc));
// s.WhenStopped((tc, hc) => tc.Stop(hc));
//}); //x.RunAsLocalService();
//x.StartAutomaticallyDelayed(); //x.SetDescription("TestQuartzJob");
//x.SetDisplayName("TestQuartzJob");
//x.SetServiceName("TestQuartzJob"); //x.EnablePauseAndContinue(); #endregion
});
}
}
}

三个配置文件(自己手动创建即可)源码:

附配置文件详解:

4.log4net.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections> <log4net>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<!--日志路径-->
<param name= "File" value= "D:\QuartzJobDemo_Log\servicelog\"/>
<!--是否是向文件中追加日志-->
<param name= "AppendToFile" value= "true"/>
<!--log保留天数-->
<param name= "MaxSizeRollBackups" value= "10"/>
<!--日志文件名是否是固定不变的-->
<param name= "StaticLogFileName" value= "false"/>
<!--日志文件名格式为:2008-08-31.log-->
<param name= "DatePattern" value= "yyyy-MM-dd&quot;.read.log&quot;"/>
<!--日志根据日期滚动-->
<param name= "RollingStyle" value= "Date"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n %loggername" />
</layout>
</appender> <!-- 控制台前台显示日志 -->
<appender name="ColoredConsoleAppender" type="log4net.Appender.ColoredConsoleAppender">
<mapping>
<level value="ERROR" />
<foreColor value="Red, HighIntensity" />
</mapping>
<mapping>
<level value="Info" />
<foreColor value="Green" />
</mapping>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%n%date{HH:mm:ss,fff} [%-5level] %m" />
</layout> <filter type="log4net.Filter.LevelRangeFilter">
<param name="LevelMin" value="Info" />
<param name="LevelMax" value="Fatal" />
</filter>
</appender> <root>
<!--(高) OFF > FATAL > ERROR > WARN > INFO > DEBUG > ALL (低) -->
<level value="all" />
<appender-ref ref="ColoredConsoleAppender"/>
<appender-ref ref="RollingLogFileAppender"/>
</root>
</log4net>
</configuration> 5.quartz.config: 这个虽然提示无效的text标记,没关系不影响 # You can configure your scheduler in either <quartz> configuration section
# or in quartz properties file
# Configuration section has precedence quartz.scheduler.instanceName = QuartzJobDemo # configure thread pool info
quartz.threadPool.type = Quartz.Simpl.SimpleThreadPool, Quartz
quartz.threadPool.threadCount = 10
quartz.threadPool.threadPriority = Normal # job initialization plugin handles our xml reading, without it defaults are used
quartz.plugin.xml.type = Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz
quartz.plugin.xml.fileNames = ~/quartz_jobs.xml # export this server to remoting context
#quartz.scheduler.exporter.type = Quartz.Simpl.RemotingSchedulerExporter, Quartz
#quartz.scheduler.exporter.port = 555
#quartz.scheduler.exporter.bindName = QuartzScheduler
#quartz.scheduler.exporter.channelType = tcp
#quartz.scheduler.exporter.channelName = httpQuartz 6.quartz_job.xml: <?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> <!--TestJob测试 任务配置-->
<job>
<name>TestJob</name>
<group>Test</group>
<description>TestJob测试</description>
<job-type>QuartzJobDemo.TestJob,QuartzJobDemo</job-type><!--命名空间.作业名,命名空间-->
<!--<job-type>QuartzJobDemo.QuartzJobs.TestJob,QuartzJobDemo</job-type>-->
<durable>true</durable>
<recover>false</recover>
</job>
<trigger>
<cron>
<name>TestJobTrigger</name>
<group>Test</group>
<job-name>TestJob</job-name>
<job-group>Test</job-group>
<start-time>2019-12-20T00:00:00+08:00</start-time>
<cron-expression>0/1 * * * * ?</cron-expression>
</cron>
</trigger> </schedule>
</job-scheduling-data>

附:配置文件详解:转自:https://www.cnblogs.com/abeam/p/8044460.html,博主总结很好(博主总结的另一篇关于任务调度的例子也很适合学习:https://www.cnblogs.com/abeam/p/8042531.html)

直接截图吧,搞一天累了:









Quartz.Net任务调度总结的更多相关文章

  1. Spring Quartz实现任务调度

    任务调度 在企业级应用中,经常会制定一些"计划任务",即在某个时间点做某件事情 核心是以时间为关注点,即在一个特定的时间点,系统执行指定的一个操作 任务调度涉及多线程并发.线程池维 ...

  2. Quartz实现任务调度

    一.任务调度概述 在企业级应用中,经常会制定一些"计划任务",即在某个时间点做某件事情,核心是以时间为关注点,即在一个特定的时间点,系统执行指定的一个操作,任务调度涉及多线程并发. ...

  3. quartz.net任务调度:源码及使用文档

    目录: 1.quartz.net任务调度:源码及使用文档 2.quartz.net插件类库封装 前言 前段时间把自己封装quartz.net 类库的过程总结到博客园,有网友想要看一下源码,所以就把源码 ...

  4. 项目ITP(五) spring4.0 整合 Quartz 实现任务调度

    前言 系列文章:[传送门] 项目需求: 二维码推送到一体机上,给学生签到扫描用.然后需要的是 上课前20分钟 ,幸好在帮带我的学长做 p2p 的时候,接触过.自然 quartz 是首选.所以我就配置了 ...

  5. 项目一:第十四天 1.在realm中动态授权 2.Shiro整合ehcache 缓存realm中授权信息 3.动态展示菜单数据 4.Quartz定时任务调度框架—Spring整合javamail发送邮件 5.基于poi实现分区导出

    1 Shiro整合ehCache缓存授权信息 当需要进行权限校验时候:四种方式url拦截.注解.页面标签.代码级别,当需要验证权限会调用realm中的授权方法   Shiro框架内部整合好缓存管理器, ...

  6. Java&Quartz实现任务调度

    目录 Java&Quartz实现任务调度 1.Quartz的作用 2.预备 3.Quartz核心 3.1.Job接口 3.2.JobDetail类 3.3 JobExecutionContex ...

  7. Quartz.Net任务调度框架

    Quartz.Net是一个开源的任务调度框架,非常强大,能够通过简单的配置帮助我们定时具体的操作. 相对于我们用的线程里面while(true)然后sleep来执行某个操作,应该算的上是高端,大气,上 ...

  8. Spring 中使用Quartz实现任务调度

    前言:Spring中使用Quartz 有两种方式,一种是继承特定的基类:org.springframework.scheduling.quartz.QuartzJobBean,另一种则不需要,(推荐使 ...

  9. ASP.NET MVC5 实现基于Quartz.NET任务调度

    工作之余.技术?.记是不可能记住的. 只有写点东西 才能维持得了生活这样子的.好早就像写一篇关于任务调度的文章.终究是太懒了 一.Quartz.NET介绍 Quartz.NET是一个强大.开源.轻量的 ...

  10. 浅谈Quartz定时任务调度

    一  开发概述 对于具有一定规模的大多数企业来说,存在着这样一种需求:存在某个或某些任务,需要系统定期,自动地执行,然而,对大多数企业来说,该技术的实现,却是他们面临的一大难点和挑战.  对于大部分企 ...

随机推荐

  1. centos查看实时网络带宽占用情况方法【转】

    Linux中查看网卡流量工具有iptraf.iftop以及nethogs等,iftop可以用来监控网卡的实时流量(可以指定网段).反向解析IP.显示端口信息等. centos安装iftop的命令如下: ...

  2. 转载:ubuntu 下添加简单的开机自启动脚本

    转自:https://www.cnblogs.com/downey-blog/p/10473939.html linux下添加简单的开机自启动脚本 在linux的使用过程中,我们经常会碰到需要将某个自 ...

  3. Android系统修改之展讯平台的Mms不能发送西班牙特殊字符ú的问题

    在测试中, 发现在发送短信的时候特殊字符ú不能发送, 但是输入框可以输入并正常显示, 查看代码之后, 发现是展讯在字符转换的时候出现的问题 frameworks/base/telephony/java ...

  4. nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'enterpriseId' in 'class java.lang.String'

    错误信息: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for p ...

  5. Apache官方强心剂:开源不受出口管理条例约束!

    开源软件到底受不受美国政府管制?这个话题最近已经成了热点,许多业内的专业人士都对此发表了看法. 对实体清单上所列合约方的出口和再出口的限制特别适用于受出口管理条例(EAR)约束的活动和交易. [1]开 ...

  6. QT textbroswer textedite Qlist的常用的操作函数

    Textbrowser: 一.添加函数 1.insertPlainText():这个函数特别好用,括号里面的参数是QString,可以用QString(“%1%2”).arg(QString变量).a ...

  7. 09Cookie&Session

    1.会话技术 1. 会话:一次会话中包含多次请求和响应.  一次会话:浏览器第一次给服务器资源发送请求,会话建立,直到有一方断开为止2. 功能:在一次会话的范围内的多次请求间,共享数据3. 方式: 1 ...

  8. lightinthebox程序bug zencart

    1.清空旧产品分类,新增分类与产品,前台首页不显示中间栏,提示无产品:布局设置 -(Main Page - Opens with Category)首页显示某分类,把新增的某分类ID填上或者设为0即可 ...

  9. mysql语句修改zencart产品原价为特价的倍数

    mysql语句修改zencart产品原价为特价的倍数,下面语句将原价设为特价的3倍: ; ;

  10. cypress

    https://community.cypress.com/docs/DOC-14090 usb3.0 only支持