定时筛选废除客户下单未开发的订单,当然介绍的园子里小说很多跟官方文档

本次是因为项目标须求:什么定时发送邮件布告,定时筛选打消客户下单未开发的订单

这一次是因为体系的需求:什么定时发送邮件公告,定时筛选废除客户下单未开发的订单

双重捡起定时器,在网上翻来找去找到—-Quartz.Net老字号了并不表示它就着实老了哦

再一次捡起定时器,在网上翻来找去找到—-Quartz.Net老字号了并不表示它就着实老了哦

github:https://github.com/quartznet/quartznet

github:https://github.com/quartznet/quartznet

理所当然介绍的园圃里作品很多跟官方文档https://www.quartz-scheduler.net介绍的都挺清楚的!用起来很轻便!

自然介绍的田园里小说很多跟官方文档https://www.quartz-scheduler.net介绍的都挺清楚的!用起来很轻便!

so!接下去本身概括介绍一下Quartz.Net框架设计 
下图借用园友的相应不会介意

so!接下去自个儿概括介绍一下Quartz.Net框架设计 
下图借用园友的应该不会介意

图片 1

图片 2

 

 

园子中查找发现早已有同学去履行了,那里引用一下各位大大的博文地址(应该不会介意,嘻嘻),我们也足以参考学习:
http://www.cnblogs.com/knowledgesea/p/5145239.html Quartz.net持久化与集群安顿开发详解
http://www.cnblogs.com/mushroom/p/4231642.html#3760225 Net作业调度(四)—quartz.net持久化和集群
http://www.cnblogs.com/lanxiaoke/p/6629481.html 职分调度之持久化(基于Quartz.net)
http://www.cnblogs.com/lanxiaoke/p/6637714.html 任务调度之集群(基于Quartz.net)
http://www.cnblogs.com/huangxincheng/p/6916246.html 使用sqlserver搭建高可用双机热备的Quartz集群布置【附源码】

园子中搜索发现已经有同学去执行了,那里引用一下各位大大的博文地址(应该不会介意,嘻嘻),我们也得以参照学习:
http://www.cnblogs.com/knowledgesea/p/5145239.html Quartz.net持久化与集群陈设开发详解
http://www.cnblogs.com/mushroom/p/4231642.html#3760225 Net作业调度(四)—quartz.net持久化和集群
http://www.cnblogs.com/lanxiaoke/p/6629481.html 职务调度之持久化(基于Quartz.net)
http://www.cnblogs.com/lanxiaoke/p/6637714.html 义务调度之集群(基于Quartz.net)
http://www.cnblogs.com/huangxincheng/p/6916246.html 利用sqlserver搭建高可用双机热备的Quartz集群布署【附源码】

在此博主自身将Quartz.net的所需类目做了一回整合,大伙可以瞅瞅**

在此博主自个儿将Quartz.net的所需类目做了一次整合,大伙能够瞅瞅**

图片 3图片 4

图片 5图片 6

 1 using Quartz;
 2 using Quartz.Impl;
 3 using System;
 4 using System.Collections.Generic;
 5 using System.Linq;
 6 using System.Text;
 7 using System.Threading.Tasks;
 8 using Wshelper.Caching;
 9 using Wshelper.Logging;
10 
11 namespace Commons.Helpers
12 {
13     public class QuartzHelper
14     {
15         /// <summary>
16         /// 时间间隔执行任务
17         /// </summary>
18         /// <typeparam name="T">任务类,必须实现IJob接口</typeparam>
19         /// <param name="seconds">时间间隔(单位:毫秒)</param>
20         public static void ExecuteInterval<T>(int seconds) where T : IJob
21         {
22             ISchedulerFactory factory = new StdSchedulerFactory();
23             IScheduler scheduler = factory.GetScheduler();
24 
25             //IJobDetail job = JobBuilder.Create<T>().WithIdentity("job1", "group1").Build();
26             IJobDetail job = JobBuilder.Create<T>().Build();
27 
28             ITrigger trigger = TriggerBuilder.Create()
29                 .StartNow()
30                 .WithSimpleSchedule(x => x.WithIntervalInSeconds(seconds).RepeatForever())
31                 .Build();
32 
33             scheduler.ScheduleJob(job, trigger);
34 
35             scheduler.Start();
36         }
37         /// <summary>
38         /// 指定时间执行任务
39         /// </summary>
40         /// <typeparam name="T">任务类,必须实现IJob接口</typeparam>
41         /// <param name="cronExpression">cron表达式,即指定时间点的表达式</param>
42         public static void ExecuteByCron<T>(string cronExpression) where T : IJob
43         {
44             ISchedulerFactory factory = new StdSchedulerFactory();
45             IScheduler scheduler = factory.GetScheduler();
46 
47             IJobDetail job = JobBuilder.Create<T>().Build();
48 
49             //DateTimeOffset startTime = DateBuilder.NextGivenSecondDate(DateTime.Now.AddSeconds(1), 2);
50             //DateTimeOffset endTime = DateBuilder.NextGivenSecondDate(DateTime.Now.AddYears(2), 3);
51 
52             ICronTrigger trigger = (ICronTrigger)TriggerBuilder.Create()
53                 //.StartAt(startTime).EndAt(endTime)
54                 .WithCronSchedule(cronExpression)
55                 .Build();
56 
57             scheduler.ScheduleJob(job, trigger);
58 
59             scheduler.Start();
60 
61             //Thread.Sleep(TimeSpan.FromDays(2));
62             //scheduler.Shutdown();
63         }
64     }
65 
66     #region 任务执行例
67     public class MyJob : IJob
68     {
69         ILogger logger = LoggerFactory.CreateLog();
70         public void Execute(IJobExecutionContext context)
71         {
72             //向c:\Quartz.txt写入当前时间并换行
73             //System.IO.File.AppendAllText(@"c:\Quartz.txt", DateTime.Now + Environment.NewLine);
74             ICache cache = new MemoryCacheFactory().Create();
75             cache.Clear();
76             logger.Info("时间:" + DateTime.Now.ToString() + "---------系统自动更新缓存!");
77         }
78     }
79     #endregion
80 }
 1 using Quartz;
 2 using Quartz.Impl;
 3 using System;
 4 using System.Collections.Generic;
 5 using System.Linq;
 6 using System.Text;
 7 using System.Threading.Tasks;
 8 using Wshelper.Caching;
 9 using Wshelper.Logging;
10 
11 namespace Commons.Helpers
12 {
13     public class QuartzHelper
14     {
15         /// <summary>
16         /// 时间间隔执行任务
17         /// </summary>
18         /// <typeparam name="T">任务类,必须实现IJob接口</typeparam>
19         /// <param name="seconds">时间间隔(单位:毫秒)</param>
20         public static void ExecuteInterval<T>(int seconds) where T : IJob
21         {
22             ISchedulerFactory factory = new StdSchedulerFactory();
23             IScheduler scheduler = factory.GetScheduler();
24 
25             //IJobDetail job = JobBuilder.Create<T>().WithIdentity("job1", "group1").Build();
26             IJobDetail job = JobBuilder.Create<T>().Build();
27 
28             ITrigger trigger = TriggerBuilder.Create()
29                 .StartNow()
30                 .WithSimpleSchedule(x => x.WithIntervalInSeconds(seconds).RepeatForever())
31                 .Build();
32 
33             scheduler.ScheduleJob(job, trigger);
34 
35             scheduler.Start();
36         }
37         /// <summary>
38         /// 指定时间执行任务
39         /// </summary>
40         /// <typeparam name="T">任务类,必须实现IJob接口</typeparam>
41         /// <param name="cronExpression">cron表达式,即指定时间点的表达式</param>
42         public static void ExecuteByCron<T>(string cronExpression) where T : IJob
43         {
44             ISchedulerFactory factory = new StdSchedulerFactory();
45             IScheduler scheduler = factory.GetScheduler();
46 
47             IJobDetail job = JobBuilder.Create<T>().Build();
48 
49             //DateTimeOffset startTime = DateBuilder.NextGivenSecondDate(DateTime.Now.AddSeconds(1), 2);
50             //DateTimeOffset endTime = DateBuilder.NextGivenSecondDate(DateTime.Now.AddYears(2), 3);
51 
52             ICronTrigger trigger = (ICronTrigger)TriggerBuilder.Create()
53                 //.StartAt(startTime).EndAt(endTime)
54                 .WithCronSchedule(cronExpression)
55                 .Build();
56 
57             scheduler.ScheduleJob(job, trigger);
58 
59             scheduler.Start();
60 
61             //Thread.Sleep(TimeSpan.FromDays(2));
62             //scheduler.Shutdown();
63         }
64     }
65 
66     #region 任务执行例
67     public class MyJob : IJob
68     {
69         ILogger logger = LoggerFactory.CreateLog();
70         public void Execute(IJobExecutionContext context)
71         {
72             //向c:\Quartz.txt写入当前时间并换行
73             //System.IO.File.AppendAllText(@"c:\Quartz.txt", DateTime.Now + Environment.NewLine);
74             ICache cache = new MemoryCacheFactory().Create();
75             cache.Clear();
76             logger.Info("时间:" + DateTime.Now.ToString() + "---------系统自动更新缓存!");
77         }
78     }
79     #endregion
80 }

View Code

View Code

 

 

启动:

启动:

图片 7图片 8

图片 9图片 10

1 public static void QuartzHelp()
2         {
3             //#region Quartz调度任务
4             string cronExpression = "1 0 0 * * ? ";  //这是指每天的0点执行任务
5             QuartzHelper.ExecuteByCron<MyJob>(cronExpression);  //这是调用Cron计划方法
6             //#endregion
7         }
1 public static void QuartzHelp()
2         {
3             //#region Quartz调度任务
4             string cronExpression = "1 0 0 * * ? ";  //这是指每天的0点执行任务
5             QuartzHelper.ExecuteByCron<MyJob>(cronExpression);  //这是调用Cron计划方法
6             //#endregion
7         }

View Code

View Code

 

 

 

 

Quartz.Net 小编曾经更新了接济.net standrad2.0了,就表示能够在.net
core平台使用了,下载地址:https://www.nuget.org/packages/Quartz/3.0.0-beta1,更新表明地方:https://www.quartz-scheduler.net/2017/10/08/quartznet-3.0-beta1-released.html,相信不久从此就会发布release版本,届时.net
core框架开发就不怕没有定时器的支撑了,~( ̄▽ ̄~)(~ ̄▽ ̄)~

Quartz.Net 作者曾经更新了帮衬.net standrad2.0了,就表示可以在.net
core平台使用了,下载地址:https://www.nuget.org/packages/Quartz/3.0.0-beta1,更新表明地点:https://www.quartz-scheduler.net/2017/10/08/quartznet-3.0-beta1-released.html,相信不久随后就会揭橥release版本,届时.net
core框架开发就不怕没有定时器的支撑了,~( ̄▽ ̄~)(~ ̄▽ ̄)~