标签:包含 automatic cep rtt sea obb account bin exec
1. Service改名
2. 添加安装程序,改名
3. ServiceInstaller->属性->StartType改为Automatic
4. ServiceProcessInstaller->属性->Account改为LocalSystem
5. App.config->属性->始终复制(为log4net做准备,可以不设置)
Service中包含了服务的初始化、启动、终止、暂停、重启等操作
1 public partial class Service : ServiceBase 2 { 3 private IScheduler scheduler; 4 5 public QuartzService() 6 { 7 InitializeComponent(); 8 ISchedulerFactory schedulerFactory = new StdSchedulerFactory(); 9 scheduler = schedulerFactory.GetScheduler(); 10 } 11 12 /// <summary> 13 /// 启动windows服务 14 /// </summary> 15 /// <param name="args">args</param> 16 protected override void OnStart(string[] args) 17 { 18 19 scheduler.Start(); 20 21 #region XXXJob 22 23 string xxx_group_name = "XXXGroup"; 24 string xxx_job_name = "XXXJob"; 25 string xxx_trigger_name = "XXXTrigger"; 26 string xxx_cron = "0/5 * * * * ?"; // 每5秒 27 IJobDetail xxx_job = JobBuilder.Create<XXXJob>() 28 .WithIdentity(xxx_job_name, xxx_group_name) 29 .Build(); 30 31 ICronTrigger xxx_trigger = (ICronTrigger)TriggerBuilder.Create() 32 .WithIdentity(xxx_trigger_name, xxx_group_name) 33 .WithCronSchedule(xxx_cron) 34 .Build(); 35 36 scheduler.ScheduleJob(xxx_job, xxx_trigger); 37 38 #endregion 39 } 40 41 /// <summary> 42 /// 终止windows服务 43 /// </summary> 44 protected override void OnStop() 45 { 46 scheduler.Shutdown(); 47 } 48 49 /// <summary> 50 /// 暂停windows服务 51 /// </summary> 52 protected override void OnPause() 53 { 54 scheduler.PauseAll(); 55 } 56 57 /// <summary> 58 /// 继续windows服务 59 /// </summary> 60 protected override void OnContinue() 61 { 62 scheduler.ResumeAll(); 63 } 64 }
1 public class XXXJob : IJob 2 { 3 public void Execute(IJobExecutionContext context) 4 { 5 throw new NotImplementedException(); 6 } 7 }
创建服务
sc create XXXService binpath= C:\XXX\XXXService.exe
删除服务
sc delete XXXService
这些还包括暂停、重启等等,都属于windows操作服务的常规命令
特别注意:
1. 附加程序
服务启动后,使用附加程序找到对应的exe即可
2. 控制台模式
[项目->属性->输出类型]改为控制台应用程序。
[项目->属性->启动对象]改为对应的Service
正式部署时,记得改回来
标签:包含 automatic cep rtt sea obb account bin exec
原文地址:https://www.cnblogs.com/simoje/p/10095736.html