Quartz.Net 简单使用
2021-03-01 02:28
标签:init 邮件 document obb add hub cto 任务 syn Open-source job scheduling system for .NET Quartz.net 是调度任务框架,我们可以用来定时发送邮件、定时处理邮件、定时统计分析数据、定时监控... 本文介绍Quartz.net的简单使用 官方Doc https://www.quartz-scheduler.net/documentation/quartz-3.x/quick-start.html 博客 https://www.cnblogs.com/z-huan/p/7412181.html 远程调度GitHub https://github.com/guryanovev/CrystalQuartz Quartz.net 启用方式大致分为三种 程序配置 XML方式配置 https://www.cnblogs.com/z-huan/p/7412181.html https://github.com/guryanovev/CrystalQuartz 更多Cron语法可参考 https://www.quartz-scheduler.net/documentation/quartz-3.x/tutorial/crontrigger.html#introduction 为job增加了特性[DisallowConcurrentExecution],可以保证当前job还未执行结束前,就算触发时间已经到了,也不能再次开启job。保证job的工作是串行进行,而非并行。在实践过程中要根据具体情况考虑是否需要增加此特性(如果还无法确定是否需要添加,建议都添加上此特性~) [DisallowConcurrentExecution] is an attribute that can be added to the Job class that tells Quartz not to execute multiple instances of a given job definition (that refers to the given job class) concurrently. https://github.com/Impartsoft/Bins/tree/main/QuartzDemo Quartz.Net 简单使用 标签:init 邮件 document obb add hub cto 任务 syn 原文地址:https://www.cnblogs.com/Iannnnnnnnnnnnn/p/14435004.html0.介绍
1. 参考资料
2.核心内容
使用总结
XML方式配置job可以参考
远程调度job可以参考GitHub
程序配置简单使用
// 实例化调度 Scheduler
StdSchedulerFactory factory = new StdSchedulerFactory();
IScheduler scheduler = await factory.GetScheduler();
await scheduler.Start();
// 定义任务
IJobDetail job = JobBuilder.Create
// Grab the Scheduler instance from the Factory
StdSchedulerFactory factory = new StdSchedulerFactory();
IScheduler scheduler = await factory.GetScheduler();
// and start it off
await scheduler.Start();
// define the job and tie it to our HelloJob class
IJobDetail helloJob = JobBuilder.Create
ITrigger goodBayTrigger = TriggerBuilder.Create()
.WithIdentity("GoodBayTrigger", "GoodBayJobGroup")
.StartNow()
.WithCronSchedule("0/10 * * * * ?")
.Build();
[DisallowConcurrentExecution]
public class HelloJob : IJob
{
public async Task Execute(IJobExecutionContext context)
{
await Console.Out.WriteLineAsync("Greetings from HelloJob!");
}
}
3.样例源码地址