记录Quarter的基本使用
-
using Quartz;
-
using Quartz.Impl;
-
using Quartz.Impl.Matchers;
-
using Quartz.Logging;
-
using System;
-
using System.Collections.Generic;
-
using System.Collections.Specialized;
-
using System.Data.Entity.Migrations;
-
using System.Linq;
-
using System.Threading;
-
using System.Threading.Tasks;
-
using System.Transactions;
-
using System.Web;
-
using WebApplication3.Models;
-
using WebApplication3.Service;
-
-
namespace WebApplication3
-
{
-
public static class QuartzHelper
-
{
-
public static async Task RunProgramRunExample()
-
{
-
try
-
{
-
// Grab the Scheduler instance from the Factory
-
NameValueCollection props = new NameValueCollection
-
{
-
{ "quartz.serializer.type", "binary" }
-
};
-
StdSchedulerFactory factory = new StdSchedulerFactory(props);
-
IScheduler scheduler = await factory.GetScheduler();
-
-
// and start it off
-
await scheduler.Start();
-
-
// define the job and tie it to our HelloJob class
-
IJobDetail job = JobBuilder.Create<HelloJob>()
-
.WithIdentity("job1", "group1")
-
.Build();
-
-
// Trigger the job to run now, and then repeat every 10 seconds
-
ITrigger trigger = TriggerBuilder.Create()
-
.WithIdentity("trigger1", "group1")
-
//将在以后的整点触发
-
.StartAt(DateBuilder.EvenHourDate(null))
-
//.StartAt(DateBuilder.FutureDate(1, IntervalUnit.Day))
-
//.StartNow()
-
//.WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(19, 36))//每天几点几分触发
-
.WithSimpleSchedule(x => x
-
.WithIntervalInHours(1)//每1小时触发
-
//.WithIntervalInMinutes(1)//每分钟
-
//.WithIntervalInSeconds(10)
-
.RepeatForever())
-
.Build();
-
-
///监听任务
-
//scheduler.ListenerManager.AddJobListener(new MyJobListener(), KeyMatcher<JobKey>.KeyEquals(new JobKey("job1", "group1")));
-
-
scheduler.ListenerManager.AddJobListener(new MyJobListener(), GroupMatcher<JobKey>.AnyGroup());
-
-
// Tell quartz to schedule the job using our trigger
-
await scheduler.ScheduleJob(job, trigger);
-
-
// and last shut down the scheduler when you are ready to close your program
-
//await scheduler.Shutdown();
-
}
-
catch (SchedulerException se)
-
{
-
Console.WriteLine(se);
-
}
-
}
-
}
-
public class MyJobListener : IJobListener
-
{
-
public string Name
-
{
-
get
-
{
-
return "监听任务";
-
}
-
}
-
public Task JobToBeExecuted(IJobExecutionContext context, CancellationToken cancellationToken = default(CancellationToken))
-
{
-
return Task.Run(() =>
-
{
-
JobToBeExecuted();
-
});
-
}
-
-
public Task JobExecutionVetoed(IJobExecutionContext context, CancellationToken cancellationToken = default(CancellationToken))
-
{
-
return Task.Run(() =>
-
{
-
JobExecutionVetoed();
-
});
-
}
-
-
public Task JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException, CancellationToken cancellationToken = default(CancellationToken))
-
{
-
return Task.Run(() =>
-
{
-
JobWasExecuted();
-
});
-
}
-
/// <summary>
-
/// 执行前
-
/// </summary>
-
public void JobToBeExecuted()
-
{
-
}
-
/// <summary>
-
/// 触发失效
-
/// </summary>
-
public void JobExecutionVetoed()
-
{
-
string path4 = System.AppDomain.CurrentDomain.BaseDirectory;
-
new Common.CommonFun().WriteLog("位置:QuartzHelper,定时器触发失效!", "autoUpdate");
-
}
-
/// <summary>
-
/// 触发完成
-
/// </summary>
-
public void JobWasExecuted()
-
{
-
}
-
}
-
/// <summary>
-
/// 定时任务
-
/// </summary>
-
public class HelloJob : IJob
-
{
-
public async Task Execute(IJobExecutionContext context)
-
{
-
await Task.Run(() =>
-
{
-
-
});
-
}
-
}
-
}
记录Quartz的基本使用
记录Quarter的基本使用的更多相关文章
- sqlserver -- 学习笔记(五)查询一天、一周、一个月记录(DateDiff 函数)(备忘)
Learn From : http://bjtdeyx.iteye.com/blog/1447300 最常见的sql日期查询的语句 --查询当天日期在一周年的数据 ) --查询当天的所有数据 ) -- ...
- sql 查询 某字段 重复次数 最多的记录
需求 查询小时气象表中 同一日期.同一城市.同意检测站点 首要污染物出现出书最多的记录 第一步: 添加 排序字段 select StationID,RecordDate,CityID,Primar ...
- C#技巧记录——持续更新
作为一名非主修C#的程序员,在此记录下学习与工作中C#的有用内容,持续更新 对类型进行约束,class指定了类型必须是引用类型,new()指定了类型必须具有一个无参的构造函数 where T : cl ...
- 04、SQL 查询当天,本月,本周的记录
SELECT * FROM 表 WHERE CONVERT(Nvarchar, dateandtime, 111) = CONVERT(Nvarchar, GETDATE(), 111) ORDE ...
- MySql: Year, Quarter, Month, Day, Hour statistics
-- 统计 select count(*) as '当天记录数' from web_product where date(p_createtime) = curdate(); select count ...
- SQL 查询当天,本月,本周的记录
SELECT * FROM 表 WHERE CONVERT(Nvarchar, dateandtime, 111) = CONVERT(Nvarchar, GETDATE(), 111) ORDE ...
- 04SQL 查询当天,本月,本周的记录
SQL 查询当天,本月,本周的记录 SELECT * FROM 表 WHERE CONVERT(Nvarchar, dateandtime, 111) = CONVERT(Nvarchar, GE ...
- mybatis使用中的记录
一: 常用sql语句: sql顺序:select [distinct] * from 表名 [where group by having order by limit]; 查询某段时间内的数据: ...
- Sql 查询当天、本周、本月记录
--查询当天: select * from info where DateDiff(dd,datetime,getdate())=0 --查询24小时内的: select * from info wh ...
随机推荐
- ICEM-哑铃(无厚度)
原视频下载地址:https://pan.baidu.com/s/1i44hdkh 密码: 96dh
- #C++初学记录(typedef和define)
typedef的用法 typedef关键字可以用于给数据类型定义一个别名,即可以给long long 定义成ll,也可以给结构体定义,当你定义了一个结构体时,每次创建一个结构体都要使用struct+结 ...
- 第12组 Beta冲刺(5/5)
Header 队名:To Be Done 组长博客 作业博客 团队项目进行情况 燃尽图(组内共享) 展示Git当日代码/文档签入记录(组内共享) 注: 由于GitHub的免费范围内对多人开发存在较多限 ...
- jmeter cookie管理器
jmeter cookie管理器 不能用正则表达式获取登录接口生成的cookie 因为cookies并不是在登录的响应结果中生成的,而是在response header中携带的,所以不能用正则表达式提 ...
- 2019年10~11月-NLP工程师求职记录
求职目标:NLP工程师 为什么想换工作? 除了技术相关书籍,我没读过太多其他类型的书,其中有一本内容短但是对我影响特别大的书--<谁动了我的奶酪>.出门问问是我毕业后的第一份工作,无论是工 ...
- NB-IoT物联网开发资料
OneNET(移动平台) https://open.iot.10086.cn/ NB-IoT套件提供了一种方便用户使用NB模组将设备连接到OneNET平台实现丰富NB-IoT应用的能力.平台为用户提供 ...
- Laya的对象唯一标识
Egret中是obj.hashcode Laya中是obj["$_GID"]
- python-机器学习-深度学习-算法-面试题
GitHub 地址: https://github.com/taizilongxu/interview_python https://github.com/imhuay/Algorithm_Inter ...
- [LeetCode] 129. Sum Root to Leaf Numbers 求根到叶节点数字之和
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number ...
- H5混合开发中android终端和ios终端常见的兼容问题1
转自 https://blog.csdn.net/xuehu837769474/article/details/80603898 1.安卓浏览器看背景图片,有些设备会模糊. 用同等比例的图片在PC机上 ...