上一篇里介绍了Job和Trigger的常用方法,这一节将介绍Calendar,它的作用是排除特定的日期时间。

 
Calendar的常用类
DailyCalendar 排除每天某个时间段任务的执行
例子:
        var sche = StdSchedulerFactory.GetDefaultScheduler();
sche.Start(); //使任务在10点到11点间不再执行
DailyCalendar cale = new DailyCalendar(
DateBuilder.DateOf(10, 0, 0).DateTime,
DateBuilder.DateOf(11, 0, 0).DateTime
);
sche.AddCalendar("myCalendar", cale, true, true);
 
WeeklyCalendar 排除每周某个星期的任务的执行
例子:
        var sche = StdSchedulerFactory.GetDefaultScheduler();
sche.Start(); WeeklyCalendar cale = new WeeklyCalendar();
cale.SetDayExcluded(DayOfWeek.Thursday, true); //让星期四不触发Schedule
//cale.SetDayExcluded(DayOfWeek.Thursday, false); //让星期四触发Schedule
sche.AddCalendar("myCalendar", cale, true, true);
 
HolidayCalendar 排除某一天的任务的执行(如果涉及到同一天跨年的情况,需要多次添加不同年份)
例子:

        var sche = StdSchedulerFactory.GetDefaultScheduler();
sche.Start(); HolidayCalendar cale = new HolidayCalendar();
cale.AddExcludedDate(DateTime.Now.AddYears(-1)); //排除去年的今天不处理
cale.AddExcludedDate(DateTime.Now); //排除今天不处理
sche.AddCalendar("myCalendar", cale, true, true);
 
MonthlyCalendar 排除每月某一天的任务的执行
例子:

        var sche = StdSchedulerFactory.GetDefaultScheduler();
sche.Start(); MonthlyCalendar cale = new MonthlyCalendar();
cale.SetDayExcluded(25, true); //排除每个月25号执行
sche.AddCalendar("myCalendar", cale, true, true);
AnnualCalendar 排除每年某一天的任务的执行
例子:

        var sche = StdSchedulerFactory.GetDefaultScheduler();
sche.Start(); AnnualCalendar cale = new AnnualCalendar();
//12月25号不执行
cale.SetDayExcluded(new DateTimeOffset(2018, 12, 25, 12, 0, 0, TimeSpan.FromHours(8)), true);
sche.AddCalendar("myCalendar", cale, true, true);
 
CronCalendar 通过Cron表达式排除任务的执行
例子:

        var sche = StdSchedulerFactory.GetDefaultScheduler();
sche.Start(); //只在营业时间执行8AM-5PM
CronCalendar cale = new CronCalendar("* * 0-7,18-23 ? * *"); sche.AddCalendar("myCalendar", cale, true, true);
 
 

Quartz.NET常用方法 02的更多相关文章

  1. 【Quartz】常用方法的使用方式(三)

    前言    总结了一下quartz组件的一些常用方法,以备将来不时之需.哈哈,看着挺简单有些好是值得笔记一下的.好记性不如烂笔头吗? 代码部分: 方法类内容: public class Example ...

  2. Quartz.NET常用方法 01

    Quartz.NET作为一款定时框架,它的最小可运行程序如下: var scheduler = StdSchedulerFactory.GetDefaultScheduler(); scheduler ...

  3. 【ios系列】-Quartz 2D常用方法介绍

    Quartz 2D基本介绍 Quartz 2D是一个二维绘图引擎 能够,绘制图形 : 线条\三角形\矩形\圆\弧等,绘制文字,绘制\生成图片(图像),读取\生成PDF,截图\裁剪图片,自定义UI控件( ...

  4. 实训第八天 有关python orm 的学习记录 常用方法02

    继续沿用第七天数据库:def test2(request): # 1.xxx__lt 小于 :查询出年龄小于22的所有 ret=models.Person.objects.filter(age__lt ...

  5. Quartz.net 2.0的使用说明

    Quartz.NET是一个开源的作业调度框架,是OpenSymphony 的 Quartz API的.NET移植,它用C#写成,可用于WinForm和ASP.NET应用中.它提供了巨大的灵活性而不牺牲 ...

  6. Quartz1.8.5例子(十)

    /* * Copyright 2005 - 2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the ...

  7. Quartz1.8.5例子(九)

    /* * Copyright 2005 - 2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the ...

  8. Quartz1.8.5例子(七)

    /* * Copyright 2005 - 2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the ...

  9. Quartz1.8.5例子(六)

    /* * Copyright 2005 - 2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the ...

随机推荐

  1. 使用 pyenv 管理不同的 Python 版本

    1. pyenv 的安装 $ yum install git -y $ yum install gcc make patch gdbm-devel openssl-devel sqlite-devel ...

  2. Apache httpd.conf配置文件 3(虚拟主机)

    ### Section 3: Virtual Hosts 第三部分 虚拟主机 注意:在使用虚拟主机前,请先检查  http.conf 的 辅助配置文件httpd-vhosts.conf 是否注释 # ...

  3. 高灵敏度自带DSP降噪算法的audio codec解决方案

    背景调研   随着AI渗透到各行各业,人们对语音的需求也越来越大,最近一两年,各种AI音频设备如雨后春笋般冒出.各种智能AI设备的推出,意味者市场对低成本的音频采集设备越来越多.针对这种情况,我们开发 ...

  4. 使用Python爬虫库BeautifulSoup遍历文档树并对标签进行操作详解(新手必学)

    为大家介绍下Python爬虫库BeautifulSoup遍历文档树并对标签进行操作的详细方法与函数下面就是使用Python爬虫库BeautifulSoup对文档树进行遍历并对标签进行操作的实例,都是最 ...

  5. Java虚拟机——JVM

    一.JVM整体架构 1.JVM(Java虚拟机):指以软件的方式模拟具有完整硬件系统功能.运行在一个完全隔离环境中的完整计算机系统,是物理机的软件实现.常用的虚拟机有VMWare.Virtual Bo ...

  6. leetcode-简单-栈-有效的括号

    给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足:  左括号必须用相同类型的右括号闭合. 左括号必须以正确的顺序闭合. 注意空字符串可被 ...

  7. Python模块之Requests

    目录 Requests 模块 常规的get请求 基于ajax的get请求 常规的post请求 基于ajax的post请求 综合项目实战 requests模块高级 requests代理 验证码处理 Re ...

  8. Java线程池中线程的生命周期

    设:我们有一个coreSize=10,maxSize=20,keepAliveTime=60s,queue=40 1.池初始化时里面没有任何线程. 2.当有一个任务提交到池就创建第一个线程. 3.若继 ...

  9. 关于...corresponds to your MySQL server version for the right syntax to use near '?' at line 1的解决办法

    完整报错信息: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual tha ...

  10. idea 工具 听课笔记 首页

    maven 创建 javaWeb站点结构标准及异常权限调整 解决Intellij Idea下修改jsp页面不自动更新(链接 idea中使用github  提交 idea 从github.com上恢复站 ...