Quartz Scheduler
程序员文章站
2022-05-04 11:06:06
using Quartz;public static class SchedulerProgram { public static void Start(IScheduler scheduler = null) { try { Assembly asm = typeof(SchedulerProgr ......
using quartz;
public static class schedulerprogram { public static void start(ischeduler scheduler = null) { try { assembly asm = typeof(schedulerprogram).gettypeinfo().assembly; type[] types = asm.gettypes(); idictionary<int, type> typemap = new dictionary<int, type>(); list<type> typelist = new list<type>(); foreach (type t in types) { if (new list<type>(t.getinterfaces()).contains(typeof(ijobscheduler))) { typelist.add(t); } } foreach (type t in typelist) { ijobscheduler schedule = objectutils.instantiatetype<ijobscheduler>(t); if (scheduler == null) { schedule.run().configureawait(false); } else { schedule.run(scheduler).configureawait(false); } } } catch (exception ex) { throw ex; } } }
public class testjobscheduler : ijobscheduler { public async task run(ischeduler scheduler) { logger.writelog("call job scheduler"); //创建任务 ijobdetail job = jobbuilder.create<testjob>(). withidentity("entityrelationshiptestjob", "crmjobgroup"). usingjobdata("jobschedulename", "entityrelationshiptestjob"). build(); //创建触发器 itrigger trigger = triggerbuilder.create().withidentity("contacttrigger", "timegroup").withsimpleschedule(t => t.withintervalinminutes(30).withrepeatcount(0)).build();// test trigger //添加任务及触发器至调度器中 await scheduler.schedulejob(job, trigger); //启动 logger.writelog("start job scheduler"); await scheduler.start(); } public task run() { throw new notimplementedexception(); } }
public interface ijobscheduler { /// <summary> /// /// </summary> /// <returns></returns> task run(); /// <summary> /// 外部传入scheduler /// </summary> /// <param name="scheduler"></param> /// <returns></returns> task run(ischeduler scheduler); }
public class testjob : ijob { public task execute(ijobexecutioncontext context) {//具体的方法 return task.fromresult(0); } }
上一篇: Maven安装与配置
下一篇: 详解计算机“死机”的八大内因
推荐阅读
-
什么是线程调度器(Thread Scheduler)和时间分片(Time Slicing )?
-
ASP.NET MVC 5 实现基于Quartz.net 的任务调度管理平台(二)
-
基于spring+quartz的分布式定时任务框架实现
-
linux定时任务访问页面代替quartz集群_html/css_WEB-ITnose
-
Spring整合Quartz实现一个简单的定时任务
-
详解MySQL用事件调度器Event Scheduler创建定时任务
-
基于Quartz定时调度任务(详解)
-
Spring整合Quartz Job以及Spring Task的实现方法
-
SpringBoot与Quartz集成实现分布式定时任务集群的代码实例
-
quartz实现定时功能实例详解(servlet定时器配置方法)