记录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 ...
随机推荐
- flume 测试 hive sink
测试flume,将数据送到hive表中,首先建表. create table order_flume( order_id string, user_id string, eval_set string ...
- GIT 使用记录,新手->会用(mac 用户)
(唔,mac 用户这个要求是因为集成在 terminal 中可直接使用) 1. github 中 创建 git 账户 2. github -> 在个人设置中 找到 ssh and GPGkey ...
- [Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available
原文链接https://blog.csdn.net/xiaomajia029/article/details/88320233 问题描述: 原因分析:在项目配置的时候,默认 npm 包导出的是运行时构 ...
- ssh密匙互信操作【原创】
1.简便ssh密匙信任方法 只在一台服务器上创建ssh-keygen [root@SMSJKSRVBJ02 ~]# ssh-keygen Generating public/private rsa k ...
- Activiti task claim
Activiti task claim claim,认领,领取 claim - 国内版 Bing https://cn.bing.com/search?FORM=U227DF&PC=U227& ...
- 【转】Jupyter Notebook主题字体设置及自动代码补全
Jupyter Notebook用久了就离不开了,然而自带的主题真的不忍直视.为了视力着想,为了自己看起来舒服,于是折腾了一番..在github上发现了一个jupyter-themes工具,可以通过p ...
- C# Newtonsoft.Json解析json字符串处理(最清晰易懂的方法)
需求: 假设有如下json字符串: { ", "employees": [ { "firstName": "Bill", &quo ...
- PHP 简易文件查看器
超简易服务器端文件查询器 代码如下: <?php // 系统入口 date_default_timezone_set("PRC"); error_reporting(E_AL ...
- Docker 安装 MySQL 并实现远程连接
获取 MySQL 镜像 docker pull mysql:5.6 查看镜像列表 docker images 启动 MySQL 镜像 docker run -itd -P mysql:5.6 bash ...
- 如何杀死处于进程状态D的进程
D状态的就是 uninterruptible sleep ,此时进程不能被信号唤醒,GDB等调试工具也不能对它调试,因为GDB也是用到了信号,也杀不死它 D状态的形成 如何分析D状态 cat /pro ...
