先貼使用代碼:

  1 using Quartz;
2 using Quartz.Impl;
3 using Quartz.Logging;
4 using System;
5 using System.Collections.Specialized;
6 using System.Threading.Tasks;
7
8 namespace QuartzTest
9 {
10 class Program
11 {
12 static void Main(string[] args)
13 {
14 GetTask().GetAwaiter().GetResult();
15 }
16 public static async Task GetTask()
17 {
18 // construct a scheduler factory
19 NameValueCollection props = new NameValueCollection
20 {
21 { "quartz.serializer.type", "binary" }
22 };
23 ISchedulerFactory factory = new StdSchedulerFactory(props);
24 IScheduler scheduler =await factory.GetScheduler();
25
26 IJobDetail job = JobBuilder.Create<HelloJob>()
27 .WithIdentity("job1", "group1")
28 .Build();
29
30 ITrigger trigger = TriggerBuilder.Create()
31 .WithIdentity("trigger1", "group1")
32 .WithCronSchedule("0/5 * * * * ?")
33 .Build();
34
35 await scheduler.ScheduleJob(job, trigger);
36 await scheduler.Start();
37
38 // some sleep to show what's happening
39 await Task.Delay(TimeSpan.FromSeconds(60));
40
41 // and last shut down the scheduler when you are ready to close your program
42 await scheduler.Shutdown();
43 }
44 }
45
46 public class HelloJob : IJob
47 {
48 public async Task Execute(IJobExecutionContext context)
49 {
50 await Console.Out.WriteLineAsync("Hello Quartz.Net..." + DateTime.Now + Environment.NewLine);
51 }
52 }
53
54
55
56 //class Program
57 //{
58 // static void Main(string[] args)
59 // {
60 // GetTask().GetAwaiter().GetResult();
61 // }
62
63 // public static async Task GetTask()
64 // {
65 // // construct a scheduler factory
66 // NameValueCollection props = new NameValueCollection
67 // {
68 // { "quartz.serializer.type", "binary" }
69 // };
70 // StdSchedulerFactory factory = new StdSchedulerFactory(props);
71
72 // // get a scheduler
73 // IScheduler scheduler =await factory.GetScheduler();
74 // await scheduler.Start();
75
76 // // define the job and tie it to our HelloJob class
77 // IJobDetail job = JobBuilder.Create<HelloJob>()
78 // .WithIdentity("myJob", "group1")
79 // .Build();
80
81 // // Trigger the job to run now, and then every 40 seconds
82 // ITrigger trigger = TriggerBuilder.Create()
83 // .WithIdentity("myTrigger", "group1")
84 // .StartNow()
85 // .WithSimpleSchedule(x => x
86 // .WithIntervalInSeconds(10)
87 // .RepeatForever())
88 // .Build();
89
90 // // Tell Quartz.Net to schedule the job using our trigger
91 // await scheduler.ScheduleJob(job, trigger);
92
93 // // some sleep to show what's happening
94 // await Task.Delay(TimeSpan.FromSeconds(60));
95
96 // // and last shut down the scheduler when you are ready to close your program
97 // await scheduler.Shutdown();
98 // }
99 //}
100
101 //public class HelloJob : IJob
102 //{
103 // public async Task Execute(IJobExecutionContext context)
104 // {
105 // await Console.Out.WriteLineAsync("Hello Quartz.Net..." + DateTime.Now + Environment.NewLine);
106 // }
107 //}
108
109
110
111 // // Other Method
112 //class Program
113 //{
114 // static void Main(string[] args)
115 // {
116 // LogProvider.SetCurrentLogProvider(new ConsoleLogProvider());
117
118 // RunProgram().GetAwaiter().GetResult();
119
120 // Console.WriteLine("Press any key to close the application");
121 // Console.ReadKey();
122 // }
123
124 // private static async Task RunProgram()
125 // {
126 // try
127 // {
128 // NameValueCollection props = new NameValueCollection
129 // {
130 // {"quartz.serializer.type", "binary" }
131 // };
132 // StdSchedulerFactory factory = new StdSchedulerFactory(props);
133 // IScheduler scheduler = await factory.GetScheduler();
134
135 // await scheduler.Start();
136
137 // IJobDetail job = JobBuilder.Create<HelloJob>()
138 // .WithIdentity("job1", "group1")
139 // .Build();
140
141 // ITrigger trigger = TriggerBuilder.Create()
142 // .WithIdentity("trigger1", "group1")
143 // .StartNow()
144 // .WithSimpleSchedule(x => x
145 // .WithIntervalInSeconds(10)
146 // .RepeatForever())
147 // .Build();
148
149 // await scheduler.ScheduleJob(job, trigger);
150
151 // await Task.Delay(TimeSpan.FromSeconds(60));
152
153 // await scheduler.Shutdown();
154 // }
155 // catch (SchedulerException se)
156 // {
157 // await Console.Error.WriteLineAsync(se.ToString());
158 // }
159 // }
160
161 // private class ConsoleLogProvider : ILogProvider
162 // {
163 // public Logger GetLogger(string name)
164 // {
165 // return (level, func, exception, parameters) =>
166 // {
167 // if (level >= LogLevel.Info && func != null)
168 // {
169 // Console.WriteLine("[" + DateTime.Now.ToLongTimeString() + "] [" + level + "] " + func(), parameters);
170 // }
171 // return true;
172 // };
173 // }
174
175 // public IDisposable OpenNestedContext(string message)
176 // {
177 // throw new NotImplementedException();
178 // }
179
180 // public IDisposable OpenMappedContext(string key, string value)
181 // {
182 // throw new NotImplementedException();
183 // }
184 // }
185 //}
186
187 //public class HelloJob : IJob
188 //{
189 // public async Task Execute(IJobExecutionContext context)
190 // {
191 // await Console.Out.WriteLineAsync("Greetings from HelloJob!");
192 // }
193 //}
194 }

參考網址:

https://www.cnblogs.com/huyong/p/11091089.html

https://www.quartz-scheduler.net/documentation/quartz-3.x/quick-start.html

https://www.liujiajia.me/2019/02/13/quartz-net/

Quartz.NET 的使用的更多相关文章

  1. 免费开源的DotNet任务调度组件Quartz.NET(.NET组件介绍之五)

    很多的软件项目中都会使用到定时任务.定时轮询数据库同步,定时邮件通知等功能..NET Framework具有“内置”定时器功能,通过System.Timers.Timer类.在使用Timer类需要面对 ...

  2. Quartz

    Quartz是一个开源的作业调度框架,它完全由Java写成,并设计用于J2SE和J2EE应用中.它提供了巨大的灵 活性而不牺牲简单性.你能够用它来为执行一个作业而创建简单的或复杂的调度. eg: ja ...

  3. Spring Quartz实现任务调度

    任务调度 在企业级应用中,经常会制定一些"计划任务",即在某个时间点做某件事情 核心是以时间为关注点,即在一个特定的时间点,系统执行指定的一个操作 任务调度涉及多线程并发.线程池维 ...

  4. topshelf和quartz内部分享

    阅读目录: 介绍 基础用法 调试及安装 可选配置 多实例支持及相关资料 quartz.net 上月在公司内部的一次分享,现把PPT及部分交流内容整理成博客. 介绍 topshelf是创建windows ...

  5. Quartz.net持久化与集群部署开发详解

    序言 我前边有几篇文章有介绍过quartz的基本使用语法与类库.但是他的执行计划都是被写在本地的xml文件中.无法做集群部署,我让它看起来脆弱不堪,那是我的罪过. 但是quart.net是经过许多大项 ...

  6. Quartz.net开源作业调度框架使用详解

    前言 quartz.net作业调度框架是伟大组织OpenSymphony开发的quartz scheduler项目的.net延伸移植版本.支持 cron-like表达式,集群,数据库.功能性能强大更不 ...

  7. quartz.net 时间表达式----- Cron表达式详解

    序言 Cron表达式:就是用简单的xxoo符号按照一定的规则,就能把各种时间维度表达的淋漓尽致,无所不在其中,然后在用来做任务调度(定时服务)的quart.net中所认知执行,可想而知这是多么的天衣无 ...

  8. Quartz.NET Windows 服务示例

    想必大家在项目中处理简单的后台持续任务或者定时触发任务的时候均使用 Thread 或者 Task 来完成,但是项目中的这种需求一旦多了的话就得将任务调度引入进来了,那今天就简单的介绍一下 Quartz ...

  9. [Quartz笔记]玩转定时调度

    简介 Quartz是什么? Quartz是一个特性丰富的.开源的作业调度框架.它可以集成到任何Java应用. 使用它,你可以非常轻松的实现定时任务的调度执行. Quartz的应用场景 场景1:提醒和告 ...

  10. 关于Quartz.NET作业调度框架的一点小小的封装,实现伪AOP写LOG功能

    Quartz.NET是一个非常强大的作业调度框架,适用于各种定时执行的业务处理等,类似于WINDOWS自带的任务计划程序,其中运用Cron表达式来实现各种定时触发条件是我认为最为惊喜的地方. Quar ...

随机推荐

  1. LLM微调方法(Efficient-Tuning)六大主流方法:思路讲解&优缺点对比[P-tuning、Lora、Prefix tuing等]

    LLM微调方法(Efficient-Tuning)六大主流方法:思路讲解&优缺点对比[P-tuning.Lora.Prefix tuing等] 由于LLM参数量都是在亿级以上,少则数十亿,多则 ...

  2. 【解决方案】Java 互联网项目中消息通知系统的设计与实现(上)

    目录 前言 一.需求分析 1.1发送通知 1.2撤回通知 1.3通知消息数 1.4通知消息列表 二.数据模型设计 2.1概念模型 2.2逻辑模型 三.关键流程设计 本篇小结 前言 消息通知系统(not ...

  3. 行为型模式(Behavioer Pattern)

    行为型设计模式 行为型模式定义了系统中对象之间的交互与通信,研究系统在运行时对象之间的相互通信与协作,进一步明确对象的职责,包括对系统中较为复杂的流程的控制. 在软件系统运行时对象并不是孤立存在的,它 ...

  4. 5分钟了解LangChain的路由链

    上上篇文章<5分钟理透LangChain的Chain>里用到了顺序链SequentialChain,它可以将多个链按顺序串起来.本文介绍LangChain里的另外1个重要的链:路由链. 1 ...

  5. 从 Docker Hub 拉取镜像受阻?这些解决方案帮你轻松应对

    最近一段时间 Docker 镜像一直是 Pull 不下来的状态,感觉除了挂,想直连 Docker Hub 是几乎不可能的.更糟糕的是,很多原本可靠的国内镜像站,例如一些大厂和高校运营的,也陆续关停了, ...

  6. dense并行训练1-流水线并行

    并行训练-流水线 简述 并行训练主要有三种策略: 数据并行训练加速比最高,但要求每个设备上都备份一份模型,显存占用比较高,但缺点是通信量大. 张量并行,通信量比较高,适合在机器内做模型并行. 流水线并 ...

  7. EF Core并发控制

    EF Core并发控制 并发控制概念 并发控制:避免多个用户同时操作资源造成的并发冲突问题. 最好的解决方案:非数据库解决方案 数据库层面的两种策略:悲观.乐观 悲观锁 悲观并发控制一般采用行锁 ,表 ...

  8. 生产环境部署Nginx服务器双机热备部署-keepalived(多种模式教程)

    前言:今天演示下生产环境keepalived的部署方式,安装模式有很多,比如说主备模型和双主模型,主备分:抢占模式 和 非抢占模式.这里我会一一展开说具体怎么配置 一.双节点均部署Nginx: 第一步 ...

  9. 基于表单登录的cookies登录

    1.基于表单登录的cookies登录 In [ ]: import requests import matplotlib.pyplot as plt from http.cookiejar impor ...

  10. [oeasy]python0018_ ASCII_字符分布_数字_大小写字母_符号_黑暗森林

    ​ 打包和解包 回忆上次内容 decode 就是解码 解码和编码可以转化 encode 编码 decode 解码 互为逆过程 大小写字母之间序号全都相差(​​32​​)​​10进制​​ ​ 编辑 这是 ...