1: using System;
2: using System.Collections.Generic;
3: using System.Linq;
4: using System.Text;
5:
6: namespace Windows.TaskSchedule
7: {
8: public interface IJob
9: {
10: void Init();
11: void Excute();
12: void OnError(Exception ex);
13: }
14: }
DemoJobhtml
1: using System;
2: using System.Collections.Generic;
3: using System.Linq;
4: using System.Text;
5:
6: namespace Windows.TaskSchedule
7: {
8: public class DemoJob:IJob
9: {
10: static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(DemoJob));
11: DateTime date = new DateTime();
12: public void Init()
13: {
14: date = DateTime.Now;
15: }
16:
17: public void Excute()
18: {
19: logger.Debug(date);
20: }
21:
22: public void OnError(Exception ex)
23: {
24: logger.Debug(ex.ToString());
25: }
26: }
27: }
Jobs.configgit
1: <?xml version="1.0" encoding="utf-8" ?>
2: <Jobs serverName="demo-server" displayName="測試服務" description="測試服務的描述">
3: <Job name="demoJob1" type="Windows.TaskSchedule.DemoJob,Windows.TaskSchedule" cornExpress="0/3 * * * * ?" />
4: </Jobs>
serverName:發佈成服務時的服務名稱(最好不要有空格)github
displayName:發佈成服務時的服務顯示名稱windows
description:發佈成服務時的服務描述框架
Job節點就是各個任務的具體配置了,name:任務的名稱(最好惟一),type:插件的具體實例與程序集,cornExpress:任務執行的時間,只支持corn表達式測試
若是是開發調試階段,能夠直接啓動Windows.TaskSchedule.exe 這樣能夠直接在控制檯輸出相關信息。spa
若是要部署成windows服務,須要在命令行下 先執行Windows.TaskSchedule.exe install 進行安裝,而後啓動:Windows.TaskSchedule.exe start插件
卸載windows服務也很簡單,直接執行 Windows.TaskSchedule.exe uninstall 具體可參考topshelf組件的使用方法。http://topshelf-project.com/命令行
想要源碼,若是你細心的話在文章的開頭就應該有啦,我仍是貼一下地址吧:https://github.com/leleroyn/Windows-TaskSchedule調試