国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

C#開發系統服務時用的定時器組件

2019-11-17 02:56:48
字體:
來源:轉載
供稿:網友
C#開發系統服務時用的定時器組件[csharp]view plaincopy
  1. //相較上一版本改進
  2. //1.修改Bug
  3. //當設置每月一次頻率時,設置的Day日期如果為31,30,29,在有些年份的有些月份會拋出異常,因為有些月份是沒有31天的,改正之后,
  4. //如果設置了31天,則只有有31天的月份會執行。
  5. //2.修正一年中某天的日期較驗功能。
  6. //3.新增加循環模式
  7. //每個月最后一天執行一次。
  8. //4.支持到秒的定時

[csharp]view plaincopy
  1. usingSystem;
  2. usingSystem.Text;
  3. usingSystem.Windows.Forms;
  4. usingUpSoft.Framework.CommonFunction.WinService;
  5. namespaceTestPRoject
  6. {
  7. ///<summary>
  8. ///測試服務
  9. ///</summary>
  10. publicclassTestServices:ServiceTimerControl
  11. {
  12. ///<summary>
  13. ///服務代碼
  14. ///</summary>
  15. protectedoverridevoidStartService()
  16. {
  17. //需要處理的服務代碼
  18. }
  19. ///<summary>
  20. ///時間配置策略名(可不重寫。默認讀配置文件中的default)
  21. ///</summary>
  22. publicoverridestringConfigName{get{return"A";}}
  23. }
  24. }
  25. 要調用時,只需輸入以下代碼
  26. newTestServices().Start();
[csharp]view plaincopy
  1. //時間策略配置,可選擇以下兩種之一,配置文件,或是重寫實現基類的獲取時間策略配置
  2. //1.代碼重寫
  3. ///<summary>
  4. ///時間策略配置
  5. ///</summary>
  6. ///<returns></returns>
  7. protectedoverrideTimerConfigGetTimerConfig()
  8. {
  9. returnnewTimerConfig{TimerMode=...,...};
  10. }
  11. //2.配置文件實現
[html]view plaincopy
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <configuration>
  3. <configSections>
  4. <sectionname="ServiceTimerConfig"type="UpSoft.Framework.CommonFunction.WinService.ServiceTimerConfigManager,CommonFunction"></section>
  5. </configSections>
  6. <ServiceTimerConfig>
  7. <!--默認采用策略-->
  8. <Default>A</Default>
  9. <!--A配置項(全節點)-->
  10. <Config>
  11. <!--A策略-->
  12. <RefName>A</RefName>
  13. <TimerMode>Interval</TimerMode>
  14. <!--延遲開始處理(單位毫秒)可為空-->
  15. <Delay>10000</Delay>
  16. <!--文件生成時間間隔(單位毫秒,1800000=30分鐘)-->
  17. <Interval>600000</Interval>
  18. <!--月份-->
  19. <MonthSeq></MonthSeq>
  20. <!--指定第幾天的序號-->
  21. <DaySeq></DaySeq>
  22. <!--定時配置-->
  23. <Times>
  24. <!--一天之中需要執行任務的時間點-->
  25. <TimeValue>11:20:19</TimeValue>
  26. <TimeValue>10:10:43</TimeValue>
  27. <TimeValue>19:10:28</TimeValue>
  28. </Times>
  29. </Config>
  30. <!--B配置項(輪詢策略)-->
  31. <Config>
  32. <!--B策略,每隔設置的時間執行一次-->
  33. <RefName>B</RefName>
  34. <TimerMode>Interval</TimerMode>
  35. <!--延遲開始處理(單位毫秒)-->
  36. <Delay>10000</Delay>
  37. <!--文件生成時間間隔(單位毫秒,1800000=30分鐘)-->
  38. <Interval>600000</Interval>
  39. </Config>
  40. <!--C配置項(天設置)-->
  41. <Config>
  42. <!--C策略,每周4在配置的時間點上執行-->
  43. <RefName>C</RefName>
  44. <TimerMode>Week</TimerMode>
  45. <!--延遲開始處理(單位毫秒)-->
  46. <Delay>10000</Delay>
  47. <!--每周的星期四的以下時間執行-->
  48. <DaySeq>4</DaySeq>
  49. <!--定時配置-->
  50. <Times>
  51. <!--一天之中需要執行任務的時間點-->
  52. <TimeValue>11:20:19</TimeValue>
  53. <TimeValue>10:10:43</TimeValue>
  54. <TimeValue>19:10:28</TimeValue>
  55. </Times>
  56. </Config>
  57. <!--D配置項(月、天設置)-->
  58. <Config>
  59. <!--D策略,每年12月8號在配置的時間點上執行-->
  60. <RefName>D</RefName>
  61. <TimerMode>Month</TimerMode>
  62. <!--延遲開始處理(單位毫秒)-->
  63. <Delay>10000</Delay>
  64. <!--月份-->
  65. <MonthSeq>12</MonthSeq>
  66. <!--天數-->
  67. <DaySeq>8</DaySeq>
  68. <!--定時配置-->
  69. <Times>
  70. <!--一天之中需要執行任務的時間點-->
  71. <TimeValue>11:20:19</TimeValue>
  72. <TimeValue>10:10:43</TimeValue>
  73. <TimeValue>19:10:28</TimeValue>
  74. </Times>
  75. </Config>
  76. </ServiceTimerConfig>
  77. </configuration>
  78. //TimerMode的定義
  79. publicenumTimerMode
  80. {
  81. ///<summary>
  82. ///輪詢方式
  83. ///</summary>
  84. Interval=0,
  85. ///<summary>
  86. ///一個月中某個天數的指定時間
  87. ///</summary>
  88. Month=1,
  89. ///<summary>
  90. ///一周中的周幾的指定時間
  91. ///</summary>
  92. Week=2,
  93. ///<summary>
  94. ///一天中的指定時間
  95. ///</summary>
  96. Day=3,
  97. ///<summary>
  98. ///一年中第幾天的指定時間
  99. ///</summary>
  100. Year=4,
  101. ///<summary>
  102. ///一年中的指定日期的指定時間
  103. ///</summary>
  104. Date=5,
  105. ///<summary>
  106. ///每個月倒數第N天
  107. ///</summary>
  108. LastDayOfMonth
  109. ///<summary>
  110. ///未設置
  111. ///</summary>
  112. NoSet
  113. }

以下是組件的源代碼

[csharp]view plaincopy
  1. usingSystem;
  2. usingSystem.Collections.Generic;
  3. usingSystem.Configuration;
  4. usingSystem.Text.RegularExpressions;
  5. usingSystem.Threading;
  6. usingSystem.Xml;
  7. namespaceUpSoft.Framework.CommonFunction.WinService
  8. {
  9. ///<summary>
  10. ///服務定時器管理
  11. ///</summary>
  12. publicabstractclassServiceTimerControl
  13. {
  14. #region私有成員
  15. ///<summary>
  16. ///定時器
  17. ///</summary>
  18. privateTimerSysTimer{get;set;}
  19. ///<summary>
  20. ///是否啟用定時器
  21. ///</summary>
  22. privatebool_EnabledTimer=true;
  23. ///<summary>
  24. ///服務執行狀態,0-休眠,1-運行
  25. ///</summary>
  26. privateint_serviceStatus=0;
  27. #endregion
  28. #region公共屬性
  29. ///<summary>
  30. ///獲取服務狀態
  31. ///</summary>
  32. publicintServiceStatus{get{return_serviceStatus;}}
  33. ///<summary>
  34. ///定時器配置
  35. ///</summary>
  36. publicTimerConfigConfig{get;set;}
  37. ///<summary>
  38. ///時間計算類
  39. ///</summary>
  40. publicTimerControlTimerControl{get;set;}
  41. ///<summary>
  42. ///配置名稱
  43. ///</summary>
  44. publicvirtualstringConfigName{get{return(ServiceTimerConfigManager.ServiceConfig==null?"":ServiceTimerConfigManager.ServiceConfig.Default);}}
  45. #endregion
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 恭城| 新泰市| 思南县| 舒兰市| 花莲市| 卓资县| 津市市| 万山特区| 泰和县| 玛纳斯县| 荣昌县| 彭山县| 泸定县| 邢台县| 汝州市| 余姚市| 财经| 沈丘县| 建湖县| 游戏| 建始县| 拜城县| 阳西县| 贞丰县| 偃师市| 三穗县| 三亚市| 石台县| 炎陵县| 碌曲县| 盐山县| 文成县| 朝阳区| 新郑市| 资中县| 牙克石市| 宜宾市| 宁陕县| 仪征市| 凯里市| 菏泽市|