记录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 ...
随机推荐
- Dense Semantic Labeling with Atrous Spatial Pyramid Pooling and Decoder for High-Resolution Remote Sensing Imagery(高分辨率语义分割)
对 Potsdam and Vaihingen 公开数据集进行处理,得到了SOTA的结果,超越DeepLab_v3+,提出的网络结构如下:结合了ASPP和FCN,UNet
- Linux环境下查看历史操作命令及清除方法(history -c)
在Linux环境中可以通过方向键的上下按键查看近期键入的命令.但这种方法只能一个一个的查看,其实系统提供了查看所有历史命令的方法. 在终端中输入以下命令查看所有命令: history [root@te ...
- ArrayList: java之ArrayList详细介绍(转)
1 ArrayList介绍 ArrayList简介 ArrayList 是一个数组队列,相当于 动态数组.与Java中的数组相比,它的容量能动态增长.它继承于AbstractList,实现了List ...
- leetcode 10. Regular Expression Matching 、44. Wildcard Matching
10. Regular Expression Matching https://www.cnblogs.com/grandyang/p/4461713.html class Solution { pu ...
- C# 实现HTTP的POST(完整可运行并且通过测试的代码)
https://blog.csdn.net/qq_21381465/article/details/80016159 我是通过VS2010 ,新建一个winform窗体项目,然后写了一个测试软件,软件 ...
- Nginx 配置 stream SSL 第四层 代理
场景:服务器F针对访问终端需要添加白名单操作,由到终端数量较多,所以用了一台代理服务器 P,在服务F中添加 服务器P IP地址的白名单,所有终端访问服务器P 由于我已经安装过 Nginx 所以只需要添 ...
- **80. Remove Duplicates from Sorted Array II 删除排序数组中的重复项 II
1. 原始题目 给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素最多出现两次,返回移除后数组的新长度. 不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件 ...
- 后会有期,江湖再见!(WondersGroup)
很高兴能和大家一路走来,一如既往的做好并做完本职工作后,今儿我要离开了,本想着悄无声息地离开,但是为了解决走了还被微信艾特和私聊找我处理问题的潜在风险,我决定在此正式的和大家说一声再见!哈哈,It's ...
- 第07组 Beta冲刺(3/4)
队名:秃头小队 组长博客 作业博客 组长徐俊杰 过去两天完成的任务:学习了很多东西 Github签入记录 接下来的计划:继续学习 还剩下哪些任务:后端部分 燃尽图 遇到的困难:自己太菜了 收获和疑问: ...
- Python 推导式详解
各种推导式详解 推导式的套路 之前我们已经学习了最简单的列表推导式和生成器表达式.但是除此之外,其实还有字典推导式.集合推导式等等. 下面是一个以列表推导式为例的推导式详细格式,同样适用于其他推导式. ...
