Quartz.Net系列(七):Trigger之SimpleScheduleBuilder详解
所有方法图

1.SimpleScheduleBuilder
RepeatForever:指定触发器将无限期重复。
WithRepeatCount:指定重复次数
var trigger = TriggerBuilder.Create().WithSimpleSchedule(s=>s.WithIntervalInSeconds().RepeatForever()).Build();
var trigger = TriggerBuilder.Create().WithSimpleSchedule(s=>s.WithIntervalInSeconds()
.WithRepeatCount()).Build();
注:底层实现是repeatCount+1,也就是总共执行repeatCount+1次
/// <summary>
/// Specify a the number of time the trigger will repeat - total number of
/// firings will be this number + 1.
/// </summary>
/// <remarks>
/// </remarks>
/// <param name="repeatCount">the number of seconds at which the trigger should repeat.</param>
/// <returns>the updated SimpleScheduleBuilder</returns>
/// <seealso cref="ISimpleTrigger.RepeatCount" />
/// <seealso cref="RepeatForever" />
public SimpleScheduleBuilder WithRepeatCount(int repeatCount)
{
this.repeatCount = repeatCount;
return this;
}

WithInterval:以毫秒为单位指定重复间隔,由于是TimeSpan也可以指定时分秒
WithIntervalInHours:以小时为单位指定重复间隔
WithIntervalInMinutes:以分钟单位指定重复间隔
WithIntervalInSeconds:以秒为单位指定重复间隔
var trigger = TriggerBuilder.Create().WithSimpleSchedule(s=>s .WithIntervalInSeconds()
.WithInterval(TimeSpan.FromDays())
.WithIntervalInMinutes()
.WithIntervalInHours()
.WithRepeatCount())
.Build();
注:底层都是通过WithInterval实现的
/// <summary>
/// Specify a repeat interval in milliseconds.
/// </summary>
/// <remarks>
/// </remarks>
/// <param name="timeSpan">the time span at which the trigger should repeat.</param>
/// <returns>the updated SimpleScheduleBuilder</returns>
/// <seealso cref="ISimpleTrigger.RepeatInterval" />
/// <seealso cref="WithRepeatCount(int)" />
public SimpleScheduleBuilder WithInterval(TimeSpan timeSpan)
{
interval = timeSpan;
return this;
} /// <summary>
/// Specify a repeat interval in seconds.
/// </summary>
/// <remarks>
/// </remarks>
/// <param name="seconds">the time span at which the trigger should repeat.</param>
/// <returns>the updated SimpleScheduleBuilder</returns>
/// <seealso cref="ISimpleTrigger.RepeatInterval" />
/// <seealso cref="WithRepeatCount(int)" />
public SimpleScheduleBuilder WithIntervalInSeconds(int seconds)
{
return WithInterval(TimeSpan.FromSeconds(seconds));
}
静态方法:
RepeatMinutelyForever
RepeatMinutelyForTotalCount
RepeatSecondlyForever
RepeatSecondlyForTotalCount
RepeatHourlyForever
RepeatHourlyForTotalCount
var trigger = TriggerBuilder.Create().WithSchedule(SimpleScheduleBuilder.RepeatSecondlyForTotalCount()).Build();
/// <summary>
/// Create a SimpleScheduleBuilder set to repeat forever with a 1 minute interval.
/// </summary>
/// <remarks>
/// </remarks>
/// <returns>the new SimpleScheduleBuilder</returns>
public static SimpleScheduleBuilder RepeatMinutelyForever()
{
SimpleScheduleBuilder sb = Create()
.WithInterval(TimeSpan.FromMinutes())
.RepeatForever(); return sb;
} /// <summary>
/// Create a SimpleScheduleBuilder set to repeat forever with an interval
/// of the given number of minutes.
/// </summary>
/// <remarks>
/// </remarks>
/// <returns>the new SimpleScheduleBuilder</returns>
public static SimpleScheduleBuilder RepeatMinutelyForever(int minutes)
{
SimpleScheduleBuilder sb = Create()
.WithInterval(TimeSpan.FromMinutes(minutes))
.RepeatForever(); return sb;
} /// <summary>
/// Create a SimpleScheduleBuilder set to repeat forever with a 1 second interval.
/// </summary>
/// <remarks>
/// </remarks>
/// <returns>the new SimpleScheduleBuilder</returns>
public static SimpleScheduleBuilder RepeatSecondlyForever()
{
SimpleScheduleBuilder sb = Create()
.WithInterval(TimeSpan.FromSeconds())
.RepeatForever(); return sb;
} /// <summary>
/// Create a SimpleScheduleBuilder set to repeat forever with an interval
/// of the given number of seconds.
/// </summary>
/// <remarks>
/// </remarks>
/// <returns>the new SimpleScheduleBuilder</returns>
public static SimpleScheduleBuilder RepeatSecondlyForever(int seconds)
{
SimpleScheduleBuilder sb = Create()
.WithInterval(TimeSpan.FromSeconds(seconds))
.RepeatForever(); return sb;
} /// <summary>
/// Create a SimpleScheduleBuilder set to repeat forever with a 1 hour interval.
/// </summary>
/// <remarks>
/// </remarks>
/// <returns>the new SimpleScheduleBuilder</returns>
public static SimpleScheduleBuilder RepeatHourlyForever()
{
SimpleScheduleBuilder sb = Create()
.WithInterval(TimeSpan.FromHours())
.RepeatForever(); return sb;
} /// <summary>
/// Create a SimpleScheduleBuilder set to repeat forever with an interval
/// of the given number of hours.
/// </summary>
/// <remarks>
/// </remarks>
/// <returns>the new SimpleScheduleBuilder</returns>
public static SimpleScheduleBuilder RepeatHourlyForever(int hours)
{
SimpleScheduleBuilder sb = Create()
.WithInterval(TimeSpan.FromHours(hours))
.RepeatForever(); return sb;
} /// <summary>
/// Create a SimpleScheduleBuilder set to repeat the given number
/// of times - 1 with a 1 minute interval.
/// </summary>
/// <remarks>
/// <para>Note: Total count = 1 (at start time) + repeat count</para>
/// </remarks>
/// <returns>the new SimpleScheduleBuilder</returns>
public static SimpleScheduleBuilder RepeatMinutelyForTotalCount(int count)
{
if (count < )
{
throw new ArgumentException("Total count of firings must be at least one! Given count: " + count);
} SimpleScheduleBuilder sb = Create()
.WithInterval(TimeSpan.FromMinutes())
.WithRepeatCount(count - ); return sb;
} /// <summary>
/// Create a SimpleScheduleBuilder set to repeat the given number
/// of times - 1 with an interval of the given number of minutes.
/// </summary>
/// <remarks>
/// <para>Note: Total count = 1 (at start time) + repeat count</para>
/// </remarks>
/// <returns>the new SimpleScheduleBuilder</returns>
public static SimpleScheduleBuilder RepeatMinutelyForTotalCount(int count, int minutes)
{
if (count < )
{
throw new ArgumentException("Total count of firings must be at least one! Given count: " + count);
} SimpleScheduleBuilder sb = Create()
.WithInterval(TimeSpan.FromMinutes(minutes))
.WithRepeatCount(count - ); return sb;
} /// <summary>
/// Create a SimpleScheduleBuilder set to repeat the given number
/// of times - 1 with a 1 second interval.
/// </summary>
/// <remarks>
/// <para>Note: Total count = 1 (at start time) + repeat count</para>
/// </remarks>
/// <returns>the new SimpleScheduleBuilder</returns>
public static SimpleScheduleBuilder RepeatSecondlyForTotalCount(int count)
{
if (count < )
{
throw new ArgumentException("Total count of firings must be at least one! Given count: " + count);
} SimpleScheduleBuilder sb = Create()
.WithInterval(TimeSpan.FromSeconds())
.WithRepeatCount(count - ); return sb;
} /// <summary>
/// Create a SimpleScheduleBuilder set to repeat the given number
/// of times - 1 with an interval of the given number of seconds.
/// </summary>
/// <remarks>
/// <para>Note: Total count = 1 (at start time) + repeat count</para>
/// </remarks>
/// <returns>the new SimpleScheduleBuilder</returns>
public static SimpleScheduleBuilder RepeatSecondlyForTotalCount(int count, int seconds)
{
if (count < )
{
throw new ArgumentException("Total count of firings must be at least one! Given count: " + count);
} SimpleScheduleBuilder sb = Create()
.WithInterval(TimeSpan.FromSeconds(seconds))
.WithRepeatCount(count - ); return sb;
} /// <summary>
/// Create a SimpleScheduleBuilder set to repeat the given number
/// of times - 1 with a 1 hour interval.
/// </summary>
/// <remarks>
/// <para>Note: Total count = 1 (at start time) + repeat count</para>
/// </remarks>
/// <returns>the new SimpleScheduleBuilder</returns>
public static SimpleScheduleBuilder RepeatHourlyForTotalCount(int count)
{
if (count < )
{
throw new ArgumentException("Total count of firings must be at least one! Given count: " + count);
} SimpleScheduleBuilder sb = Create()
.WithInterval(TimeSpan.FromHours())
.WithRepeatCount(count - ); return sb;
} /// <summary>
/// Create a SimpleScheduleBuilder set to repeat the given number
/// of times - 1 with an interval of the given number of hours.
/// </summary>
/// <remarks>
/// <para>Note: Total count = 1 (at start time) + repeat count</para>
/// </remarks>
/// <returns>the new SimpleScheduleBuilder</returns>
public static SimpleScheduleBuilder RepeatHourlyForTotalCount(int count, int hours)
{
if (count < )
{
throw new ArgumentException("Total count of firings must be at least one! Given count: " + count);
} SimpleScheduleBuilder sb = Create()
.WithInterval(TimeSpan.FromHours(hours))
.WithRepeatCount(count - ); return sb;
}
Quartz.Net系列(七):Trigger之SimpleScheduleBuilder详解的更多相关文章
- MongoDB副本集配置系列七:MongoDB oplog详解
1:oplog简介 oplog是local库下的一个固定集合,Secondary就是通过查看Primary 的oplog这个集合来进行复制的.每个节点都有oplog,记录这从主节点复制过来的信息,这样 ...
- SpringBoot系列(十二)过滤器配置详解
SpringBoot(十二)过滤器详解 往期精彩推荐 SpringBoot系列(一)idea新建Springboot项目 SpringBoot系列(二)入门知识 springBoot系列(三)配置文件 ...
- 深入浅出Mybatis系列(四)---配置详解之typeAliases别名(mybatis源码篇)
上篇文章<深入浅出Mybatis系列(三)---配置详解之properties与environments(mybatis源码篇)> 介绍了properties与environments, ...
- Android Studio系列教程五--Gradle命令详解与导入第三方包
Android Studio系列教程五--Gradle命令详解与导入第三方包 2015 年 01 月 05 日 DevTools 本文为个人原创,欢迎转载,但请务必在明显位置注明出处!http://s ...
- 构建安全的Xml Web Service系列之wse之错误代码详解
原文:构建安全的Xml Web Service系列之wse之错误代码详解 WSE3.0现在还没有中文版的可以下载,使用英文版的过程中,难免会遇到各种各样的错误,而面对一堆毫无头绪的错误异常,常常会感到 ...
- [js高手之路] es6系列教程 - 对象功能扩展详解
第一:字面量对象的方法,支持缩写形式 //es6之前,这么写 var User = { name : 'ghostwu', showName : function(){ return this.nam ...
- “全栈2019”Java第七十章:静态内部类详解
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...
- [转帖]Linux系列之SAR命令使用详解
Linux系列之SAR命令使用详解 sar是System Activity Reporter(系统活动情况报告)的缩写.这个工具所需要的负载很小,也是目前linux中最为全面的性能分析工具之一.此款工 ...
- 【面试题】JS第七种数据类型Symbol详解
JS第七种数据类型Symbol详解 点击打开视频讲解更加详细 一.什么是Symbol? Symbol是ES6中引入的一种新的基本数据类型,用于表示一个独一无二的值.它是JavaScript中的第 七种 ...
随机推荐
- 自动网络搜索(NAS)在语义分割上的应用(二)
前言: 本文将介绍如何基于ProxylessNAS搜索semantic segmentation模型,最终搜索得到的模型结构可在CPU上达到36 fps的测试结果,展示自动网络搜索(NAS)在语义分割 ...
- pytest 使用
import pytestfrom web_ui_YXBI.test_datas.common_datas import Common_Datas as cfrom selenium import w ...
- 重学 Java 设计模式:实战建造者模式
作者:小傅哥 博客:https://bugstack.cn - 原创系列专题文章 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 乱码七糟 [luàn qī bā zāo],我时常怀疑这个成语 ...
- Android_存储之scoped storage&媒体文件
Scoped storage 文件存储介绍了内部存储和外部存储相关的内容.因为外部存储容易读写,所以在手机中经常看到很多“乱七八糟”的文件或文件夹,这些就是应用肆意创建的. Android Q(10) ...
- CentOS 安装 git2.x.x 版本
方法一 源码方式安装 第一步:卸载旧的git版本. $ yum remove git 第二步:下载git $ wget --no-check-certificate https://www.kerne ...
- git的相关基础操作
一.git安装 从https://git-scm.com/下载相应版本安装即可,一路默认安装到底即可,安装目录可以自行选择 二.git配置 安装完git后在任意文件夹内单击鼠标右键,会出现Git GU ...
- mybatis精讲(七)--动态sql
目录 常用标签 if元素 choose元素 trim元素 forearch bind元素 在我们传统的开发中我们会通过拼接sql达到数据库的操作.java中的拼接不仅效率低下而且代码很长不易维护.而M ...
- ActiveMQ 笔记(一)概述与安装
个人博客网:https://wushaopei.github.io/ (你想要这里多有) 一.消息中间件的产生背景 1.前言:考虑消息中间件的使用场景? 在何种场景下需要使用消息中间件 为什么要 ...
- 蓝桥杯(Java方法、详细解法分析)基础练习 阶乘计算
问题描述 给定n和len,输出n!末尾len位. 输入格式 一行两个正整数n和len. 输出格式 一行一个字符串,表示答案.长度不足用前置零补全. 样例输入 6 5 样例输出 00720 数据规模和约 ...
- (Java实现) 洛谷 P1091合唱队形
题目描述 NN位同学站成一排,音乐老师要请其中的(N−K)位同学出列,使得剩下的KK位同学排成合唱队形. 合唱队形是指这样的一种队形:设K位同学从左到右依次编号为1,2,-,K1,2,-,K,他们的身 ...