PollingTask.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. using UAS_PLCDataReader.Entity;
  6. namespace UAS_PLCDataReader.PublicMethod
  7. {
  8. class PollingTask
  9. {
  10. /// <summary>
  11. /// 内部调用的任务,添加了取消标识符号
  12. /// </summary>
  13. Dictionary<string, Task> InTask = new Dictionary<string, Task>();
  14. /// <summary>
  15. /// 获取任务
  16. /// </summary>
  17. /// <param name="TCode"></param>
  18. /// <returns></returns>
  19. public Task GetTask(int TID)
  20. {
  21. return null;
  22. }
  23. /// <summary>
  24. /// 添加任务,默认添加后自动执行,返回创建的TASK的ID
  25. /// </summary>
  26. /// <param name="TCode"></param>
  27. /// <returns></returns>
  28. //public void AddTask(Action action, string Code)
  29. //{
  30. // Task newTask = Task.Factory.StartNew(() => action);
  31. // InTask.Add(Code, newTask);
  32. //}
  33. /// <summary>
  34. /// 添加任务,默认添加后自动执行,返回创建的TASK的ID
  35. /// </summary>
  36. /// <param name="TCode"></param>
  37. /// <returns></returns>
  38. public void AddTask(Action<object> action, Polling obj)
  39. {
  40. Task.Factory.StartNew(action, obj);
  41. }
  42. /// 添加一系列任务
  43. /// </summary>
  44. /// <param name="action"></param>
  45. public void AddTask(Action[] action)
  46. {
  47. }
  48. /// <summary>
  49. /// 添加任务
  50. /// </summary>
  51. /// <param name="TCode"></param>
  52. /// <returns></returns>
  53. public int AddTask(Action action, bool AutoStart)
  54. {
  55. return 0;
  56. }
  57. /// <summary>
  58. /// 移除任务
  59. /// </summary>
  60. /// <returns></returns>
  61. public bool RemoveTask(string Code)
  62. {
  63. InTask.Remove(Code);
  64. return true;
  65. }
  66. /// <summary>
  67. /// 移除所有的任务
  68. /// </summary>
  69. /// <returns></returns>
  70. public bool RemoveAllTask()
  71. {
  72. InTask.Clear();
  73. return true;
  74. }
  75. /// <summary>
  76. /// 暂停任务
  77. /// </summary>
  78. /// <param name="TID"></param>
  79. /// <returns></returns>
  80. public bool PauseTask(int TID)
  81. {
  82. return true;
  83. }
  84. /// <summary>
  85. /// 开启所有任务
  86. /// </summary>
  87. public void StartAllTask()
  88. {
  89. foreach (var item in InTask)
  90. {
  91. item.Value.Start();
  92. }
  93. }
  94. ///// <summary>
  95. ///// 暂停所有任务
  96. ///// </summary>
  97. //public void PauseAllTask()
  98. //{
  99. //
  100. //}
  101. /// <summary>
  102. /// 停止所有任务
  103. /// </summary>
  104. public void StopAllTask()
  105. {
  106. }
  107. /// <summary>
  108. /// 停止指定任务
  109. /// </summary>
  110. /// <param name="TID"></param>
  111. /// <returns></returns>
  112. public bool StopTask(int TID)
  113. {
  114. return true;
  115. }
  116. }
  117. }