• quartz.net 执行后台任务


    ...

    https://www.cnblogs.com/zhangweizhong/category/771057.html

    https://www.cnblogs.com/lanxiaoke/category/973331.html

    宿主在控制台程序中

    using System;
    using System.Collections.Specialized;
    using System.IO;
    using System.Threading.Tasks;
    using Quartz;
    using Quartz.Impl;
    using Ace;
    using Microsoft.Extensions.Configuration;
    using Ace.Application.CS;

    namespace CS.QuartzJob
    {
    public class Program
    {
    private static void Main(string[] args)
    {
    var configuration = new ConfigurationBuilder()
    .SetBasePath(Directory.GetCurrentDirectory())
    .AddJsonFile("config.json", true, true)
    .Build();
    Globals.Configuration = configuration;

    RunProgram().GetAwaiter().GetResult();

    Console.WriteLine("Press any key to close the application");
    Console.Read();
    }

    private static async Task RunProgram()
    {
    try
    {
    // Grab the Scheduler instance from the Factory
    NameValueCollection props = new NameValueCollection
    {
    { "quartz.serializer.type", "binary" }
    };
    StdSchedulerFactory factory = new StdSchedulerFactory(props);
    IScheduler scheduler = await factory.GetScheduler();
    await scheduler.Start();

    var cron1 = Globals.Configuration["JobCron:Job1"];
    // 项目完成状态
    IJobDetail job = JobBuilder.Create<ProjectDoneJob>()
    .WithIdentity("job1", "group1")
    .Build();
    ICronTrigger trigger = (ICronTrigger)TriggerBuilder.Create()
    .WithIdentity("trigger1")
    .WithCronSchedule(cron1)//cron触发器
    .ForJob("job1", "group1")
    .Build();
    await scheduler.ScheduleJob(job, trigger);

    }
    catch (SchedulerException se)
    {
    await Console.Error.WriteLineAsync(se.ToString());
    }
    }
    }

    public class ProjectDoneJob : IJob
    {
    public async Task Execute(IJobExecutionContext context)
    {

    await Console.Out.WriteLineAsync( DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
    }
    }
    }

    config.json,设置始终复制

    {

    "JobCron": {
    "Job1": "0 0/1 * * * ?" //1分钟
    }

    }

  • 相关阅读:
    Intellij IDEA13 创建多模块Maven项目
    oracle锁
    oracle rac负载均衡
    awk命令
    政务外网、政务专网、政务内网和互联网
    图片切换实现选中-未选中效果
    生成带logo 的二维码
    控制input为number时样式
    移动端适配的解决方法?
    input-checkbox选中及非选中样式设置
  • 原文地址:https://www.cnblogs.com/langhaoabcd/p/10446229.html
Copyright © 2020-2023  润新知