惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
N
Netflix TechBlog - Medium
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
F
Full Disclosure
V
Visual Studio Blog
aimingoo的专栏
aimingoo的专栏
NISL@THU
NISL@THU
S
Schneier on Security
T
The Exploit Database - CXSecurity.com
P
Privacy International News Feed
Latest news
Latest news
C
CERT Recently Published Vulnerability Notes
P
Privacy & Cybersecurity Law Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
CXSECURITY Database RSS Feed - CXSecurity.com
AWS News Blog
AWS News Blog
C
Cybersecurity and Infrastructure Security Agency CISA
L
Lohrmann on Cybersecurity
Apple Machine Learning Research
Apple Machine Learning Research
The GitHub Blog
The GitHub Blog
T
Tor Project blog
A
About on SuperTechFans
博客园 - 司徒正美
P
Proofpoint News Feed
T
Threat Research - Cisco Blogs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Jina AI
Jina AI
Microsoft Security Blog
Microsoft Security Blog
Blog — PlanetScale
Blog — PlanetScale
罗磊的独立博客
Security Latest
Security Latest
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Hugging Face - Blog
Hugging Face - Blog
云风的 BLOG
云风的 BLOG
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
L
LINUX DO - 热门话题
Know Your Adversary
Know Your Adversary
T
Tenable Blog
K
Kaspersky official blog
Simon Willison's Weblog
Simon Willison's Weblog
宝玉的分享
宝玉的分享
有赞技术团队
有赞技术团队
Cisco Talos Blog
Cisco Talos Blog
U
Unit 42
T
The Blog of Author Tim Ferriss
T
Threatpost
D
DataBreaches.Net
Engineering at Meta
Engineering at Meta
P
Palo Alto Networks Blog

博客园 - 家中慢步

AKShare 高频请求东财数据接口的异常问题及解决方案 quartz 2.2.1 jdbc 连接池参数配置 httpclient发送request请求时设置header和timeout redmine 安装roadmap 插件 centos 下自动备份redmine 数据 centos 5.6 安装redmine 步骤 解决mysql 写入中文读出乱码的问题 SVN的Redmine集成插件 Quartz.net Tutorial Lesson 2 Redmine 导入AD用户 RedMine 邮件通知配置 teamlab与redmine试用对比报告 Redmine集成LDAP认证 Redmine 初体验 jqgrid 属性说明 [原创]sql server inner join 效率测试 为sql server客户端连接添加别名 [转载]sql server T-SQL 区分字符串大小写 的两种方法 [转载]sql server 常用存储过程
Quartz.net Tutorial Lesson 1
家中慢步 · 2011-08-18 · via 博客园 - 家中慢步

第一课:使用Quartz.net

关键字:

IschedulerFactory:调度工厂

IScheduler:调度器

IJob:任务

JobDetail:任务明细

Trigger:任务触发器

在我们使用scheduler之前,它需要被实例化,因此,我们使用了一个IschedulerFactory的实现。

一旦scheduler被实例化,它可以被启动,并处于备用模式(我们可以理解为监听状态),并且可以被关闭, 注意:一旦一个scheduler被关闭,除非重新实例化,否则它无法重新启动。并且scheduler必须在启动状态,并且非暂停状态,triggers才可以执行。

下面是一段简单的实例代码,如何创建并启动一个scheduler实例,并且如何调度一个任务的执行。

config:

View Code

<?xml version="1.0"?>
<configuration>
<configSections>
<section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</configSections>
<quartz>
<add key="quartz.scheduler.instanceName" value="ExampleDefaultQuartzScheduler"/><add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz"/>
<add key="quartz.threadPool.threadCount" value="10"/>
<add key="quartz.threadPool.threadPriority" value="2"/><add key="quartz.jobStore.misfireThreshold" value="60000"/>
<add key="quartz.jobStore.type" value="Quartz.Simpl.RAMJobStore, Quartz"/>
</quartz>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>

jobImpl

View Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Quartz;namespace QuartzConsoleDemo
{
class PrintDate : IJob
{
public void Execute(JobExecutionContext context)
{
Console.WriteLine(DateTime.Now.ToString(
"yyyy-MM-dd"));
}
}
class PrintHello : IJob
{
public void Execute(JobExecutionContext context)
{
Console.WriteLine(
"Hello, Guys!");
}
}
}

program

View Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Quartz;
using Quartz.Impl;namespace QuartzConsoleDemo
{
class Program
{
static void Main(string[] args)
{
// 创建调度工厂
ISchedulerFactory schedFact = new StdSchedulerFactory();
// 创建一个调度实例
IScheduler sched = schedFact.GetScheduler();
// 开始执行调度任务
sched.Start();// 添加一个执行明细(任务)
JobDetail job = new JobDetail("PrintDate", null, typeof(PrintDate));
// 添加一个触发器(任务何时|何种条件下执行)
Trigger trig = new SimpleTrigger("trig");
Trigger trigger
= TriggerUtils.MakeSecondlyTrigger(1);
trigger.StartTimeUtc
= TriggerUtils.GetEvenMinuteDate(DateTime.UtcNow);
trigger.Name
= "PrintTrigger";
// 将执行明细和触发器加入调度器的监控
sched.ScheduleJob(job, trigger);

JobDetail jobHello

= new JobDetail("PrintHello", null, typeof(PrintHello));
Trigger trigger1
= TriggerUtils.MakeSecondlyTrigger(2);
trigger1.StartTimeUtc
= TriggerUtils.GetEvenMinuteDate(DateTime.UtcNow);
trigger1.Name
= "PrintHelloTrigger";
sched.ScheduleJob(jobHello, trigger1);
}
}
}

原文地址:http://quartznet.sourceforge.net/tutorial/lesson_1.html

Lesson 1: Using Quartz

Before you can use the scheduler, it needs to be instantiated (who'd have guessed?). To do this, you use an implementor of ISchedulerFactory.

Once a scheduler is instantiated, it can be started, placed in stand-by mode, and shutdown. Note that once a scheduler is shutdown, it cannot be restarted without being re-instantiated. Triggers do not fire (jobs do not execute) until the scheduler has been started, nor while it is in the paused state.

Here's a quick snippet of code, that instantiates and starts a scheduler, and schedules a job for execution:

// construct a scheduler factory
ISchedulerFactory schedFact = new StdSchedulerFactory();

// get a scheduler
IScheduler sched = schedFact.GetScheduler();
sched.Start();

// construct job info
JobDetail jobDetail = new JobDetail("myJob", null, typeof(HelloJob));
// fire every hour
Trigger trigger = TriggerUtils.MakeHourlyTrigger();
// start on the next even hour
trigger.StartTimeUtc = TriggerUtils.GetEvenHourDate(DateTime.UtcNow);  
trigger.Name = "myTrigger";
sched.ScheduleJob(jobDetail, trigger); 

As you can see, working with Quartz.NET is rather simple. In Lesson 2 we'll give a quick overview of Jobs and Triggers, so that you can more fully understand this example.