在项目Nuget包管理器中搜索:quartz,安装完成之后再项目中引用即可

先定义一个Job,需要实现IJob接口:

public class TestJob : IJob
{
public void Execute(IJobExecutionContext context)
{
log4net.ILog log = log4net.LogManager.GetLogger(typeof(TestJob));
if (log.IsInfoEnabled)
{
log.Info("记录当前时间" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")+"\r\n");
}
Console.WriteLine("执行调度任务test"+" --- "+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
}
}

配置quartz_jobs.xml(附Cron生成器链接)

<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>
<!--任务名称,同一个group中多个job的name不能相同-->
<name>SimpleJob</name>
<!--任务分组-->
<group>sampleGroup</group>
<!--任务描述-->
<description>Sample job for Quartz Server</description>
<!--完整命名空间的类名及所属程序集名称-->
<job-type>WindowsService.Job.SimpleJob, WindowsService</job-type>
<durable>true</durable>
<recover>false</recover>
</job>
<!--任务触发器-->
<trigger>
<!--简单任务的触发器,可以调度用于重复执行的任务-->
<!--<simple>
--><!--触发器名称,同一个分组中的名称必须不同--><!--
<name>sampleSimpleTrigger</name>
--><!--触发器组--><!--
<group>sampleGroup</group>
--><!--描述--><!--
<description>Simple trigger to simply fire sample job</description>
--><!--要调度的任务名称,该job-name必须和对应job节点中的name完全相同--><!--
<job-name>SimpleJob</job-name>
--><!--调度任务(job)所属分组,该值必须和job中的group完全相同--><!--
<job-group>sampleGroup</job-group>
--><!--任务开始时间--><!--
--><!--<start-time>--21T11::+:</start-time>--><!--
<misfire-instruction>SmartPolicy</misfire-instruction>
--><!--任务执行次数 - 为无限次执行--><!--
<repeat-count>-</repeat-count>
--><!--任务触发间隔(毫秒)--><!--
<repeat-interval></repeat-interval>
--><!--每3秒中执行一次--><!--
</simple>-->
<cron>
<name>JobTrigger</name>
<group>JobTriggers</group>
<description>cron trigger</description>
<job-name>SimpleJob</job-name>
<job-group>sampleGroup</job-group>
<!--<start-time>--26T22::+:</start-time>-->
<cron-expression>0/2 * * * * ?</cron-expression>
</cron>
</trigger>
</schedule>
</job-scheduling-data>

配置quartz.config文件(在此提醒下,配置这个文件文件中会出现红色波浪错误提示,这个不影响最终结果)

# You can configure your scheduler in either <quartz> configuration section
# or in quartz properties file
# Configuration section has precedence
quartz.scheduler.instanceName = ServerScheduler
# configure thread pool info
quartz.threadPool.type = Quartz.Simpl.SimpleThreadPool, Quartz
quartz.threadPool.threadCount =
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 =
quartz.scheduler.exporter.bindName = QuartzScheduler
quartz.scheduler.exporter.channelType = tcp
quartz.scheduler.exporter.channelName = httpQuartz

main函数中进行调用

static void Main(string[] args)
{
StdSchedulerFactory std = new StdSchedulerFactory();
IScheduler scheduler = std.GetScheduler();
scheduler.Start();
}

运行结果,每隔两秒输出语句

quartz.net使用(通过配置文件进行配置)的更多相关文章

  1. Quartz 在 Spring 中如何动态配置时间--转

    原文地址:http://www.iteye.com/topic/399980 在项目中有一个需求,需要灵活配置调度任务时间,并能自由启动或停止调度. 有关调度的实现我就第一就想到了Quartz这个开源 ...

  2. Quartz实现JAVA定时任务的动态配置

    什么是动态配置定时任务? 首先说下这次主题,动态配置.没接触过定时任务的同学可以先看下此篇:JAVA定时任务实现的几种方式 定时任务实现方式千人千种,不过基础的无外乎 1.JDK 的Timer类 2. ...

  3. 使用配置文件来配置JDBC连接数据库

    1.管理数据库连接的Class 代码如下: package jdbcTest;import java.sql.Connection;import java.sql.DriverManager;impo ...

  4. Log4net配置文件一般配置

    配置文件一般配置 <?xml version="1.0"?> <configuration> <configSections> <sect ...

  5. hibernate3整合spring2时hibernate即用注解又用配置文件情况时spring配置文件的配置写法

    hibernate只用注解时,spring的配置文件的配置如下 <bean id="dataSource" class="org.apache.commons.db ...

  6. 01_MyBatis EHCache集成及所需jar包,ehcache.xml配置文件参数配置及mapper中的参数配置

     1 与mybatis集成时需要的jar ehcache-core-2.6.5.jar mybatis-ehcache-1.0.2.jar Mybatis.日志.EHCache所需要的jar包如下 ...

  7. shell 环境变量的相关配置文件和配置方法

    shell 环境变量的相关配置文件和配置方法: bash 的配置文件: 全局配置: /etc/profile, /etc/profile.d/*.sh, /etc/bashrc 个人配置 ~/.bas ...

  8. Mybatis-基于配置文件的配置(——纪念这个即将被抛弃的孩子)

    虽然内心相信Mybatis基于配置文件的配置早已经在实战之中被注解所遗忘,但是我相信还是会有一小部分人还是需要这种技术去维护原有使用这种方式去搭建的项目. 废话不多说首先使用框架包是不能少的了.导入M ...

  9. SpringBoot学习(三)-->Spring的Java配置方式之读取外部的资源配置文件并配置数据库连接池

    三.读取外部的资源配置文件并配置数据库连接池 1.读取外部的资源配置文件 通过@PropertySource可以指定读取的配置文件,通过@Value注解获取值,具体用法: @Configuration ...

随机推荐

  1. 解决mydql执行sql文件时报Error: Unknown storage engine 'InnoDB'的错误。

    我运行了一个innoDB类型的sql文件,报了Error: Unknown storage engine 'InnoDB'错误,网上查了很多方法,但是都没办法真正解决我的问题,后来解决了,在这里总结一 ...

  2. Spring mybatis源码篇章-SqlSessionFactoryBean

    前言:通过实例结合源码的方式解读,其中涉及到的文件来自于博主的Github毕设项目SchoolActivity_WxServer,引用的jar包为mybatis-spring-1.3.0.jar Sp ...

  3. 【html】 a 标签

    摘要 嗷呜,发现好多前端细节,基础不扎实啊,喵了个咪 target 属性 在制定框架中打开 <a href="a.html" target="view_frame& ...

  4. Python学习记录----IDE安装

    摘要: 安装eric5 一 确定python版本 安装的最新版本:python3.3 下载连接:http://www.python.org/getit/ 二 确定pyqt版本 安装的最新版本:PyQt ...

  5. Java复习随笔

    1.StringTokenizer str = new StringTokenizer("字符串"); str.countTokns();   //可得出字符串非连续的个数(可用于 ...

  6. centos6.8 静默安装 oracle 11.2.0.4

    安装环境及系统要求    (下文具体参数值与路径根据自己的环境调整)操作系统:Red Hat Enterprise Linux 6 (x86) 或者CentOS 6 (x64) 数据库:Oracle ...

  7. webpack开发与生产环境配置

    前言 作者去年就开始使用webpack, 最早的接触就来自于vue-cli.那个时候工作重点主要也是 vue 的使用,对webpack的配置是知之甚少,期间有问题也是询问大牛 @吕大豹.顺便说一句,对 ...

  8. 枪战Maf[POI2008]

    题目描述 有n个人,每个人手里有一把手枪.一开始所有人都选定一个人瞄准(有可能瞄准自己).然后他们按某个顺序开枪,且任意时刻只有一个人开枪.因此,对于不同的开枪顺序,最后死的人也不同. 输入 输入n人 ...

  9. Linux Command Line(I): Beginner

    考試月終於暫告一段落,終於有時間回歸Linux 的懷抱.不知怎的,在VMware Workstation 12 上登入Ubuntu後總是blue screen,明明昨天用terminal 也沒有事啊真 ...

  10. java类的继承,多态,抽象类与接口

    知识点梳理:     1,怎样定义自己的类. MyStarFrame,MyStarPanel 类中定义: (1)属性(数据),变量. (2)方法(函数),行为. (3)构造方法(特征,作用,何时被调用 ...