一、导入NuGet

 二、创建一个类并实现接口Ijob,并实现该接口中的方法。

using Buday.Gold.Cusumer.Lib;
using Quartz;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace Quartz.CheckoutService
{
public class JobInterest : IJob
{
public Task Execute(IJobExecutionContext context)
{
return Task.Run(() =>
{
//在此处实现作业的业务逻辑
Console.WriteLine(""); });
} }
}

三、使用

using Quartz;
using Quartz.Impl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace Buday.Gold.Cusumer.CheckoutService
{
class Program
{
static void Main(string[] args)
{
var scheduler = StdSchedulerFactory.GetDefaultScheduler().GetAwaiter().GetResult();
//创建触发条件
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("InterestTrigger", "Interest")
.StartNow()
.WithDailyTimeIntervalSchedule(t =>
{
t.OnEveryDay();//每天都执行
t.StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(, ));//设置执行的开始时间
//只设置开始时间,会在开始以后一直执行
t.EndingDailyAt(TimeOfDay.HourAndMinuteOfDay(, ));//设置停止执行的时间
//二者表示,开某个时间段执行
t.WithIntervalInHours();//执行的间隔
})
.Build();
//创建作业内容
IJobDetail job = JobBuilder.Create(typeof(JobInterest))
.WithIdentity("InterestJob", "Interest")
.Build();
scheduler.ScheduleJob(job, trigger);
scheduler.Start();
}
}
}
四、收集的一些 ITrigger 属性说明:

1.WithSimpleSchedule:
指定从某一个时间开始,以一定的时间间隔(单位是毫秒)执行的任务。
.WithSimpleSchedule(t => {
t.RepeatForever();//重复次数不限
//上下两者取其一
t.WithRepeatCount();//设置重复次数,例如5次
t.WithIntervalInHours();//设置执行间隔
//上下两者取其一
t.WithInterval(new TimeSpan(, , ));//设置重复间隔,用具体的小时,分钟,秒
})
2.WithCalendarIntervalSchedule:
和WithSimpleSchedule类似,不同的是.SimpleSchedule指定的重复间隔只有(时,分,秒)而CalendarIntervalSchedule可以时(年,月,周,天,时,分,秒)
.WithCalendarIntervalSchedule(t => {
t.WithIntervalInDays();//间隔以天为单位
t.WithIntervalInWeeks();//间隔以周为单位
t.WithIntervalInMonths();//间隔以月为单位
t.WithIntervalInYears();//间隔以年为单位
})
3.WithDailyTimeIntervalSchedule:
指定每天的某个时间段内,以一定的时间间隔执行任务。并且它可以支持指定星期
.WithDailyTimeIntervalSchedule(t => {
t.OnEveryDay();//每天执行
t.OnDaysOfTheWeek(DayOfWeek.Monday,DayOfWeek.Saturday);//每周的星期几执行
t.OnMondayThroughFriday();//设置工作日执行(周一至周五)
t.OnSaturdayAndSunday();//设置周末执行
t.StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(,));//设置执行的开始时间
//只设置开始时间,会在开始以后一直执行
t.EndingDailyAt(TimeOfDay.HourAndMinuteOfDay(, ));//设置停止执行的时间
//二者表示,开某个时间段执行
t.WithIntervalInHours();//设置重复间隔(更据方法不同可是时,分,秒)
t.WithRepeatCount();//设置总共执行次数
})
4.StartNow()和.StartAt(new DateTimeOffset(new DateTime(2018,1,10))):
StartNow:表示启动后立即执行一次.
StartAt:表示启动后在指定日期或时间开始执行
5.WithCronTrigger:
以表达的形式定义触发条件

C# 使用Quartz简单实例以及备忘的更多相关文章

  1. 定时执行程序-Quartz简单实例

    1.加jar包:Quartz自己quartz-1.8.3.jar和依赖包commons-logging.jar  .slf4j-log4j12-1.5.10.jar .slf4j-api-1.5.10 ...

  2. Quartz简单实例

    Quartz中提供了两种触发器,分别是CronTrigger和SimpleTrigger. 1. SimpleTrigger 每隔若干毫秒来触发纳入进度的任务. 2. CronTrigger 在特定& ...

  3. c3p0-config.xml文件简单说明与备忘

    <?xml version="1.0" encoding="UTF-8"?> <c3p0-config> <named-confi ...

  4. MySQL的简单使用方法备忘

    这只是一篇我的个人备忘录,写的是我常用的命令.具体可以参考"菜鸟教程" https://www.runoob.com/mysql/mysql-tutorial.html 登录(用户 ...

  5. Colletion View 简单的备忘

    UIColletionView 这篇只是做UIColletionView的常用属性.代理方法和数据源方法的备忘,之后做一些自定义布局,增加删除动画等. UIColletionViewFlowLayou ...

  6. 个人 WPF+EF(DBFirst) 简单应用开发习惯及EF学习测试(备忘) -- 2

    接上篇:个人 WPF+EF(DBFirst) 简单应用开发习惯及EF学习测试(备忘) -- 1 Step1 在主程序中设置连接数据库 从Model类库的 App.Config 把数据库字符串拷贝出来, ...

  7. Spring boot 注解简单备忘

    Spring boot 注解简单备忘 1.定义注解 package com.space.aspect.anno;import java.lang.annotation.*; /** * 定义系统日志注 ...

  8. 简单备忘一下Linux下的wget和curl如何使用http proxy

    简单备忘一下Linux下的wget和curl如何使用http proxywget -e "http_proxy=porxyhost:port" www.baidu.comcurl ...

  9. get_template_part() 函数详解备忘(转)

    最近研究官方主题 Twenty Eleven ,有一些东西网上现成的中文资料不好找,在博客里记载下来,算是分享,也算是备忘,wordpress 3.0 以后就开始便有了get_template_par ...

随机推荐

  1. SqlServer 禁止架构更改的复制中手动修复使发布和订阅中分别增加的字段同步

    原文:SqlServer 禁止架构更改的复制中手动修复使发布和订阅中分别增加的字段同步 由于之前的需要,禁止了复制架构更改,以至在发布中添加一个字段,并不会同步到订阅中,而现在又在订阅中添加了一个同名 ...

  2. nginx 简单应用

    从源代码编译 Nginx 把源码解压缩之后,在终端里运行如下命令: $ ./configure $ make $ sudo make install 默认情况下,Nginx 会被安装在 /usr/lo ...

  3. 解释下Func<T, bool> exp

    比如 interface IRepository<T> where T:class { IEnumerable<T> FindAll(Func<T, bool> e ...

  4. 在Window和Linux下使用Zthread库(跨平台高级面向对象的线性和sycnchronization 库)

    ZThread库是一个开源的跨平台高级面向对象的线性和sycnchronization 库,以运行POSIX 和Win32 系统中的C++程序. ZThread库的主页:http://zthread. ...

  5. easyui在IE中: SCRIPT1003: 缺少 ':'

  6. Codility---Dominator

    Task description A zero-indexed array A consisting of N integers is given. The dominator of array A ...

  7. 《SpringMVC从入门到放肆》十五、SpringMVC之上传文件

    上一篇我们学习了数据分组校验,已经可以灵活的在项目中进行数据校验了,今天来学习SpringMVC的上传文件功能.相对来说SpringMVC的上传功能,还是比较简单的. 一.添加依赖 <depen ...

  8. Android项目开发之--------地铁时光机(一,搭建主框架)

    一:先看一下框架搭建后的效果图      , 二:框架结构 (1)底部导航栏采用的是: MainActivity(主框架), MsgFragment(首页), HistoryFragment(历史清单 ...

  9. spring boot 2.x 系列 —— spring boot 实现分布式 session

    文章目录 一.项目结构 二.分布式session的配置 2.1 引入依赖 2.2 Redis配置 2.3 启动类上添加@EnableRedisHttpSession 注解开启 spring-sessi ...

  10. 戏说 .NET GDI+系列学习教程(一、Graphics类--纸)

    Graphics类(纸) Graphics类封装一个GDI+绘图图面,提供将对象绘制到显示设备的方法,Graphics与特定的设备上下文关联. 画图方法都被包括在Graphics类中,在画任何对象时, ...