C#-Windows服务+Quartz定时任务
2021-01-20 13:13
标签:settings task tin 理想 evel ati div async shu C#-Windows服务+Quartz定时任务 标签:settings task tin 理想 evel ati div async shu 原文地址:https://www.cnblogs.com/ywkcode/p/12129084.html 1 public class UpdateJob : IJob
2 {
3
4 public async Task Execute(IJobExecutionContext context)
5 {
6 try
7 {
8 await Task.Run(() => UpdateJobFun());
9 }
10 catch (Exception ex)
11 {
12 await Task.Run(() => LogHelper.WriteLogs(""));
13 throw ex;
14 }
15 }
16 public void UpdateJobFun()
17 {
18 //日志记录
19 LogHelper.WriteLogs("当前时间为:"+DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
20 }
21 }
1 public class JobScheduler
2 {
3 //调度器工厂
4 private static readonly ISchedulerFactory factory = null;
5 //调度器
6 private static readonly IScheduler scheduler = null;
7 //定时规则
8 public static string QuartzCron =
9 ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).AppSettings.Settings["QuartzCron"].Value; //
10 static JobScheduler()
11 {
12 //创建一个工厂
13 factory = new StdSchedulerFactory();
14 scheduler = factory.GetScheduler().Result;
15 scheduler.Start();
16 }
17 public static void Start()
18 {
19
20 scheduler.GetJobGroupNames();
21 IJobDetail job;
22 ITrigger trigger;
23 //创建任务
24 //Quartz.JobBuilder.Create
1 public partial class QuartzService : ServiceBase
2 {
3
4 private IScheduler scheduler;
5 public QuartzService()
6 {
7 InitializeComponent();
8
9 }
10 protected override void OnStart(string[] args)
11 {
12 JobScheduler.Start();
13 }
14 protected override void OnStop()
15 {
16 JobScheduler.OnStop();
17 }
18 }
文章标题:C#-Windows服务+Quartz定时任务
文章链接:http://soscw.com/index.php/essay/44551.html