配置文件說明
app.config中的quartz部分
???????? <quartz>
?????????????????? <!-- configure Thread Pool-->
?????????????????? <addkey="quartz.threadPool.type"value="Quartz.Simpl.SimpleThreadPool,Quartz" />
?????????????????? <addkey="quartz.threadPool.threadCount"value="10" />
?????????????????? <addkey="quartz.threadPool.threadPriority"value="Normal" />
?????????????????? <!-- configure Job Store-->
?????????????????? <addkey="quartz.jobStore.misfireThreshold"value="60000" />
?????????????????? <addkey="quartz.jobStore.type"value="Quartz.Simpl.RAMJobStore,Quartz" />
?????????????????? <!-- configure scheduler-->
?????????????????? <addkey="quartz.scheduler.instanceName"value="ServiceScheduler" />
?????????????????? <!-- configure jobs and triggersdefinition-->
?????????????????? <addkey="quartz.plugin.xml.type"value="Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin,Quartz" />
?????????????????? <addkey="quartz.plugin.xml.fileNames"value="~/quartz_jobs.xml" />
<!—重新掃描配置文件的間隔時間(單位:s)-->
?????????????????? <addkey="quartz.plugin.xml.scanInterval"value="2" />
???????? </quartz>
quartz_jobs.xml
job??
??????? <job>
??????? <name>TestJob</name>
??????? <group>TestJobGroup</group>
??????? <description>測試Job </description>
??????? <job-type>Company.WindowsService.Jobs.TestJob,Company.WindowsService</job-type>
??????? <durable>true</durable>
??????? <recover>false</recover>
</job>
Trigger_simple(簡單任務觸發器)
??? <trigger>
????? <simple>
??????? <name>TestJobTrigger</name>
??????? <group>TestJobTriggerGroup</group>
??????? <description>測試Job觸發器</description>
??????? <job-name>TestJob</job-name>
??????? <job-group>TestJobGroup</job-group>
??????? <misfire-instruction>SmartPolicy</misfire-instruction>
<!—(必填)任務執行次數.-1表示無限次執行; 3表示執行3次-->
??????? <repeat-count>3</repeat-count>
?????????????????? <!—(必填)任務觸發間隔(毫秒),1000表示每1秒執行一次-->
??????? <repeat-interval>1000</repeat-interval>
????? </simple>
</trigger>
Trigger_Cron(復雜任務觸發器)
??? <trigger>
????? <cron>
??????? <name>TestJobTrigger</name>
??????? <group>TestJobTriggerGroup</group>
??????? <description>測試Job觸發器</description>
??????? <job-name>TestJob</job-name>
??????? <job-group>TestJobGroup</job-group>
?????????????????? <!-- -->
??????? <misfire-instruction>SmartPolicy</misfire-instruction>
?????????????????? <!-- -->
??????? <cron-expression>0030 09 * * ?</cron-expression>
????? </cron>
??? </trigger>
cron-expression規則
1.??????由6到7個用空格分開的字段組成
2.??????字段間順序和格式如下
序號 | 必填 | 意義 | 數據格式 | 特殊字符 |
1 | 是 | Second | 0-59 | , - * / |
2 | 是 | Minutes | 0-59 | , - * / |
3 | 是 | Hour | 0-23 | , - * / |
4 | 是 | Day of Month | 1-31 | , - * ? / L W C |
5 | 是 | Month | 1-12 JAN-DEC | , - * / |
6 | 是 | Day of Week | 1-7 SUN-SAT | , - * ? / L C # |
7 | 否 | Year | 1970-2099 | , - * / |
特殊字符說明
名稱 | 意義 | 示例 |
, | 附加值 | MON,WED,FRI在Day of Week中表示周一,三,五 |
- | 范圍 | 10-12在Month中表示10到12月 |
* | 通配符,表示任何值 | *在Minutes表示每分鐘 |
/ | 增量 | 0/15在Minutes中表示從0分開始,每15分鐘,即0,15,30,45 |
? | 不指定特殊的值 | ? |
L | Last,最后一個 | L在Day of Month表示某月的最后一天;L在Day of Week中表示星期六(數學7); L可與數字組合使用,6L在Day of Month中表示某個月的最后一個星期六 |
W | ? | ? |
C | ? | ? |
# | ? | ? |
?