原文:记录Quarter的基本使用



  1. using Quartz;
  2. using Quartz.Impl;
  3. using Quartz.Impl.Matchers;
  4. using Quartz.Logging;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Collections.Specialized;
  8. using System.Data.Entity.Migrations;
  9. using System.Linq;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. using System.Transactions;
  13. using System.Web;
  14. using WebApplication3.Models;
  15. using WebApplication3.Service;
  16. namespace WebApplication3
  17. {
  18. public static class QuartzHelper
  19. {
  20. public static async Task RunProgramRunExample()
  21. {
  22. try
  23. {
  24. // Grab the Scheduler instance from the Factory
  25. NameValueCollection props = new NameValueCollection
  26. {
  27. { "quartz.serializer.type", "binary" }
  28. };
  29. StdSchedulerFactory factory = new StdSchedulerFactory(props);
  30. IScheduler scheduler = await factory.GetScheduler();
  31. // and start it off
  32. await scheduler.Start();
  33. // define the job and tie it to our HelloJob class
  34. IJobDetail job = JobBuilder.Create<HelloJob>()
  35. .WithIdentity("job1", "group1")
  36. .Build();
  37. // Trigger the job to run now, and then repeat every 10 seconds
  38. ITrigger trigger = TriggerBuilder.Create()
  39. .WithIdentity("trigger1", "group1")
  40. //将在以后的整点触发
  41. .StartAt(DateBuilder.EvenHourDate(null))
  42. //.StartAt(DateBuilder.FutureDate(1, IntervalUnit.Day))
  43. //.StartNow()
  44. //.WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(19, 36))//每天几点几分触发
  45. .WithSimpleSchedule(x => x
  46. .WithIntervalInHours(1)//每1小时触发
  47. //.WithIntervalInMinutes(1)//每分钟
  48. //.WithIntervalInSeconds(10)
  49. .RepeatForever())
  50. .Build();
  51. ///监听任务
  52. //scheduler.ListenerManager.AddJobListener(new MyJobListener(), KeyMatcher<JobKey>.KeyEquals(new JobKey("job1", "group1")));
  53. scheduler.ListenerManager.AddJobListener(new MyJobListener(), GroupMatcher<JobKey>.AnyGroup());
  54. // Tell quartz to schedule the job using our trigger
  55. await scheduler.ScheduleJob(job, trigger);
  56. // and last shut down the scheduler when you are ready to close your program
  57. //await scheduler.Shutdown();
  58. }
  59. catch (SchedulerException se)
  60. {
  61. Console.WriteLine(se);
  62. }
  63. }
  64. }
  65. public class MyJobListener : IJobListener
  66. {
  67. public string Name
  68. {
  69. get
  70. {
  71. return "监听任务";
  72. }
  73. }
  74. public Task JobToBeExecuted(IJobExecutionContext context, CancellationToken cancellationToken = default(CancellationToken))
  75. {
  76. return Task.Run(() =>
  77. {
  78. JobToBeExecuted();
  79. });
  80. }
  81. public Task JobExecutionVetoed(IJobExecutionContext context, CancellationToken cancellationToken = default(CancellationToken))
  82. {
  83. return Task.Run(() =>
  84. {
  85. JobExecutionVetoed();
  86. });
  87. }
  88. public Task JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException, CancellationToken cancellationToken = default(CancellationToken))
  89. {
  90. return Task.Run(() =>
  91. {
  92. JobWasExecuted();
  93. });
  94. }
  95. /// <summary>
  96. /// 执行前
  97. /// </summary>
  98. public void JobToBeExecuted()
  99. {
  100. }
  101. /// <summary>
  102. /// 触发失效
  103. /// </summary>
  104. public void JobExecutionVetoed()
  105. {
  106. string path4 = System.AppDomain.CurrentDomain.BaseDirectory;
  107. new Common.CommonFun().WriteLog("位置:QuartzHelper,定时器触发失效!", "autoUpdate");
  108. }
  109. /// <summary>
  110. /// 触发完成
  111. /// </summary>
  112. public void JobWasExecuted()
  113. {
  114. }
  115. }
  116. /// <summary>
  117. /// 定时任务
  118. /// </summary>
  119. public class HelloJob : IJob
  120. {
  121. public async Task Execute(IJobExecutionContext context)
  122. {
  123. await Task.Run(() =>
  124. {
  125. });
  126. }
  127. }
  128. }

记录Quartz的基本使用

发布了7 篇原创文章 · 获赞 2 · 访问量 6323

记录Quarter的基本使用的更多相关文章

  1. sqlserver -- 学习笔记(五)查询一天、一周、一个月记录(DateDiff 函数)(备忘)

    Learn From : http://bjtdeyx.iteye.com/blog/1447300 最常见的sql日期查询的语句 --查询当天日期在一周年的数据 ) --查询当天的所有数据 ) -- ...

  2. sql 查询 某字段 重复次数 最多的记录

    需求  查询小时气象表中 同一日期.同一城市.同意检测站点  首要污染物出现出书最多的记录 第一步: 添加 排序字段 select StationID,RecordDate,CityID,Primar ...

  3. C#技巧记录——持续更新

    作为一名非主修C#的程序员,在此记录下学习与工作中C#的有用内容,持续更新 对类型进行约束,class指定了类型必须是引用类型,new()指定了类型必须具有一个无参的构造函数 where T : cl ...

  4. 04、SQL 查询当天,本月,本周的记录

    SELECT * FROM 表 WHERE CONVERT(Nvarchar, dateandtime, 111) = CONVERT(Nvarchar, GETDATE(), 111)   ORDE ...

  5. MySql: Year, Quarter, Month, Day, Hour statistics

    -- 统计 select count(*) as '当天记录数' from web_product where date(p_createtime) = curdate(); select count ...

  6. SQL 查询当天,本月,本周的记录

    SELECT * FROM 表 WHERE CONVERT(Nvarchar, dateandtime, 111) = CONVERT(Nvarchar, GETDATE(), 111)   ORDE ...

  7. 04SQL 查询当天,本月,本周的记录

    SQL 查询当天,本月,本周的记录   SELECT * FROM 表 WHERE CONVERT(Nvarchar, dateandtime, 111) = CONVERT(Nvarchar, GE ...

  8. mybatis使用中的记录

    一: 常用sql语句: sql顺序:select [distinct] * from 表名 [where group by having order by limit]; 查询某段时间内的数据:    ...

  9. Sql 查询当天、本周、本月记录

    --查询当天: select * from info where DateDiff(dd,datetime,getdate())=0 --查询24小时内的: select * from info wh ...

随机推荐

  1. vCenter线上操作磁盘扩容

    以下截图是生产机器,目前是有一块盘,且根分区是/dev/sda3,因为磁盘不足,需要备份的数据要远远超过此时的空间大小:正常情况下,是可以新增硬盘硬盘作为备份 但是作为宿主机下的虚机,因为一些不规范的 ...

  2. vim 注释颜色

    方法一 修改 vim 配置文件 /etc/vim/vimrc (1)用vim打开 /etc/vim/vimrc文件 (2)按大写 ‘G’ 到最后一行,插入   hi comment ctermfg=6 ...

  3. Fluent Meshing对称模型形成完整模型

    原视频下载地址:https://pan.baidu.com/s/1i4NZnVZ 密码:ts5a

  4. Spring Boot YML 掀翻 Properties!!

    .properties 配置文件大家应该都很熟悉,键值对嘛,.yml 配置文件栈长也是从 Spring Boot 开始了解到的. 那么,这两种格式的配置文件到底有哪些区别呢?哪个更好?能不能替换代替? ...

  5. server2003 IIS6.0 网站不可用

    事件 ID ( 487 )的描述(在资源( Zend Optimizer )中)无法找到.本地计算机可能没有必要的注册信息或消息 DLL 文件来从远程计算机显示消息.您可能可以使用 /AUXSOURC ...

  6. [转]c++ pthread 多线程简介

    链接:https://blog.csdn.net/u013894427/article/details/83827173 pthread 入口函数类型说明void * func1(void * t)v ...

  7. Laya的Tween缓动没有初始化repeat导致的Bug

    当你使用一个Tween给一个图标做旋转动画,循环播放.(repeat是播放次数, repeat=0无限循环,repeat=1播放一次) Laya.Tween.to(this.light,{rotati ...

  8. Java8 Stream流方法

    流是Java API的新成员,它允许以声明性方式处理数据集合(通过查询语句来表达,而不是临时编写一个实现).就现在来说,可以把它们看成遍历数据集的高级迭代器.此外,流还可以透明地并行处理,无需写任何多 ...

  9. piecewise_construct存在的意义

    C++11中大部分的容器对于添加元素除了传统的 insert 或者 pusb_back/push_front 之外都提供一个新的函数叫做 emplace. 比如如果你想要向 std::vector 的 ...

  10. ingress Whitelisting白名单机制

    Whitelisting To restrict the service in a way that only a list of IPs can access it, modify the ingr ...