我是靠谱客的博主 贤惠冰淇淋,这篇文章主要介绍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分钟
}

}

转载于:https://www.cnblogs.com/langhaoabcd/p/10446229.html

最后

以上就是贤惠冰淇淋最近收集整理的关于quartz.net 执行后台任务的全部内容,更多相关quartz.net内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(134)

评论列表共有 0 条评论

立即
投稿
返回
顶部