c# 任务调度篇QuartZ(第四部分:配置添加任务文件使用)

主要改写的代码

//IJobDetail sayHijobDetail = JobBuilder.Create<SayHIJob>()
//    .WithDescription("this is sayHijobDetail")
//.WithIdentity("SayhiJob", "Vip高级班")
//.WithDescription("This is SayhiJob")
//.Build();

//ITrigger SayhiTrigger = TriggerBuilder.Create()
//               .WithIdentity("SayhiTrigger", "Vip高级班")
//               //.StartAt(new DateTimeOffset(DateTime.Now.AddSeconds(10)))
//               .StartNow()
//              .WithCronSchedule("1/4 * * * * ?")  
//              .WithDescription("This is SayhiJob's SayhiTrigger")
//              .Build();

await scheduler.ScheduleJob(sayHijobDetail, SayhiTrigger);

//使用配置文件
XMLSchedulingDataProcessor processor = new XMLSchedulingDataProcessor(new SimpleTypeLoadHelper());
await processor.ProcessFileAndScheduleJobs("~/CfgFiles/quartz_jobs.xml", scheduler);

配置文件代码

<?xml version="1.0" encoding="UTF-8"?>
<job-scheduling-data xmlns="http://quartznet.sourceforge.net/JobSchedulingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0">
  
  <processing-directives>
    <overwrite-existing-data>true</overwrite-existing-data>
  </processing-directives>
  <schedule>
    <job>
      <name>SayhiJob</name>
      <group>Vip高级班</group>
      <description>this is sayHijobDetail</description>
      <job-type>DispatcherProject.QuartzNet.CustomJob.SayHIJob,DispatcherProject.QuartzNet</job-type>
      <durable>true</durable>
      <recover>false</recover>
    </job>
    <trigger>
      <cron>
        <name>SayhiJobTrigger</name>
        <group>Vip高级班</group>
        <job-name>SayhiJob</job-name>
        <job-group>Vip高级班</job-group>
        <cron-expression>0/3 * * * * ?</cron-expression>
      </cron>
    </trigger>
    
    
    <!--<job>
      <name>UpdateInventoryJob</name>
      <group>Update</group>
      <description>定时更新商品库存</description>
      <job-type>TopshelfAndQuartz.UpdateInventoryJob,TopshelfAndQuartz</job-type>
      <durable>true</durable>
      <recover>false</recover>
    </job>
    <trigger>
      <cron>
        <name>UpdateInventoryTrigger</name>
        <group>Update</group>
        <job-name>UpdateInventoryJob</job-name>
        <job-group>Update</job-group>
        <cron-expression>0 0/1 * * * ?</cron-expression>
      </cron>
    </trigger>-->
  </schedule>
</job-scheduling-data>

注意:配置文件属性需要改写始终复制

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 代码科技 设计师:Amelia_0503 返回首页