Topshelf + Quartz2.5 创建基于windows服务
2021-03-28 17:27
标签:use hmm space down reading lease sso ado let 1.创建一个定时调度Quartz类 2.创建用于处理业务逻辑的类 3.创建quartz.config配置文件 4.创建定时job的配置信息xml文件 5.主函数入口 注:每次修改完quartz_jobs.xml文件后, 需重新生成项目,将quartz_jobs.xml 复制到当前项目bin\Release目录下。 Topshelf + Quartz2.5 创建基于windows服务 标签:use hmm space down reading lease sso ado let 原文地址:https://www.cnblogs.com/-xyl/p/9319072.html 1 using Quartz;
2 using Quartz.Impl;
3 using System;
4 using System.Collections.Generic;
5 using System.Linq;
6 using System.Text;
7 using System.Threading.Tasks;
8 using Topshelf;
9
10
11 namespace TopShelfSolution
12 {
13
14 public sealed class QuartzServiceRunner :ServiceControl,ServiceSuspend
15 {
16 private readonly IScheduler scheduler;
17
18 public QuartzServiceRunner()
19 {
20 scheduler = StdSchedulerFactory.GetDefaultScheduler();
21 }
22
23 public bool Start(HostControl hostControl)
24 {
25 scheduler.Start();
26 return true;
27 }
28
29 public bool Stop(HostControl hostControl)
30 {
31 scheduler.Shutdown(false);
32 return true;
33 }
34
35 public bool Continue(HostControl hostControl)
36 {
37 scheduler.ResumeAll();
38 return true;
39 }
40
41 public bool Pause(HostControl hostControl)
42 {
43 scheduler.PauseAll();
44 return true;
45 }
46
47 }
48 }
1 using Quartz;
2 using System;
3 using System.Collections.Generic;
4 using System.Linq;
5 using System.Text;
6 using System.Threading.Tasks;
7
8
9
10 namespace TopShelfSolution.QuartzJobs
11 {
12 public sealed class QuartzJobForTest :IJob
13 {
14 public void Execute(IJobExecutionContext context)
15 {
16 //处理业务逻辑
17 Console.WriteLine(DateTime.Now.ToString("yyyyMMddhhmmssfff"));
18
19 }
20 }
21 }
# You can configure your scheduler in either
"1.0" encoding="UTF-8"?>
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading;
6 using System.Threading.Tasks;
7 using System.Timers;
8 using Topshelf;
9
10 namespace TopShelfSolution
11 {
12 class Program
13 {
14 static void Main(string[] args)
15 {
16 HostFactory.Run(u =>
17 {
18 u.Service
文章标题:Topshelf + Quartz2.5 创建基于windows服务
文章链接:http://soscw.com/index.php/essay/69149.html