记录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 ...
随机推荐
- I Count Two Three(打表+排序+二分查找)
I Count Two Three 二分查找用lower_bound 这道题用cin,cout会超时... AC代码: /* */ # include <iostream> # inclu ...
- mysql 创建分组
mysql> select * from table1; +----------+------------+-----+---------------------+ | name_new | t ...
- 不能对以下表使用 TRUNCATE TABLE
1.由 FOREIGN KEY 约束引用的表.(您可以截断具有引用自身的外键的表.) 2.参与索引视图的表. 3.通过使用事务复制或合并复制发布的表. 4.对于具有以上一个或多个特征的表,请使用 DE ...
- Pycharm使用git版本控制
一.使用Pycharm进行版本控制 01 从远程仓库克隆项目 从远程仓库将一个已存在的项目克隆到本地 打开pycharm, VCS --> Checkout from Version Contr ...
- [C++] const和mutable关键字使用方法
const 修饰的变量为常成员变量,表示此变量不能被修改赋值,并且构造函数中只能用初始化列表的方式初始化,其他初始化方式都是错误的 const 修饰的函数为常成员函数,表示此函数中只能读取成员变量,不 ...
- Tensorflow r1.12及tensorflow serving r1.12 GPU版本编译遇到的问题
1.git clone tensorflow serving 及tensorflow代码 2. ERROR: /root/.cache/bazel/_bazel_root/f71d782da17fd8 ...
- WAL streaming (max_wal_senders > 0) requires wal_level "replica" or "logical"
初次使用pg的11版本,执行以下操作修改归wal_level设置: alter system set set wal_level='minimal'; 尝试重启pg,发现重启失败,并报错: waiti ...
- js实现字符串切割并转换成对象格式保存到本地
// split() 将字符串按照指定的规则分割成字符串数组,并返回此数组(字符串转数组的方法) //分割字符串 var bStr = "www.baidu.con"; var a ...
- WebGL学习笔记(二):WebGL坐标系及基础几何概念
WebGL使用的是正交右手坐标系,且每个方向都有可使用的值的区间,超出该矩形区间的图像不会绘制: x轴最左边为-1,最右边为1: y轴最下边为-1,最上边为1: z轴朝向你的方向最大值为1,远离你的方 ...
- docker安装并运行mongo
拉镜像: [mall@VM_0_7_centos ~]$ sudo docker pull mongo:3.2 [sudo] password for mall: 3.2: Pulling from ...
