123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- using System;
- using System.Collections.Generic;
- using System.Threading;
- using System.Threading.Tasks;
- using UAS_PLCDataReader.Entity;
- namespace UAS_PLCDataReader.PublicMethod
- {
- class PollingTask
- {
- /// <summary>
- /// 内部调用的任务,添加了取消标识符号
- /// </summary>
- Dictionary<string, Task> InTask = new Dictionary<string, Task>();
- /// <summary>
- /// 获取任务
- /// </summary>
- /// <param name="TCode"></param>
- /// <returns></returns>
- public Task GetTask(int TID)
- {
- return null;
- }
- /// <summary>
- /// 添加任务,默认添加后自动执行,返回创建的TASK的ID
- /// </summary>
- /// <param name="TCode"></param>
- /// <returns></returns>
- //public void AddTask(Action action, string Code)
- //{
- // Task newTask = Task.Factory.StartNew(() => action);
- // InTask.Add(Code, newTask);
- //}
-
- /// <summary>
- /// 添加任务,默认添加后自动执行,返回创建的TASK的ID
- /// </summary>
- /// <param name="TCode"></param>
- /// <returns></returns>
- public void AddTask(Action<object> action, Polling obj)
- {
- Task.Factory.StartNew(action, obj);
- }
- /// 添加一系列任务
- /// </summary>
- /// <param name="action"></param>
- public void AddTask(Action[] action)
- {
- }
- /// <summary>
- /// 添加任务
- /// </summary>
- /// <param name="TCode"></param>
- /// <returns></returns>
- public int AddTask(Action action, bool AutoStart)
- {
- return 0;
- }
- /// <summary>
- /// 移除任务
- /// </summary>
- /// <returns></returns>
- public bool RemoveTask(string Code)
- {
- InTask.Remove(Code);
- return true;
- }
- /// <summary>
- /// 移除所有的任务
- /// </summary>
- /// <returns></returns>
- public bool RemoveAllTask()
- {
- InTask.Clear();
- return true;
- }
- /// <summary>
- /// 暂停任务
- /// </summary>
- /// <param name="TID"></param>
- /// <returns></returns>
- public bool PauseTask(int TID)
- {
- return true;
- }
- /// <summary>
- /// 开启所有任务
- /// </summary>
- public void StartAllTask()
- {
- foreach (var item in InTask)
- {
- item.Value.Start();
- }
- }
- ///// <summary>
- ///// 暂停所有任务
- ///// </summary>
- //public void PauseAllTask()
- //{
- //
- //}
- /// <summary>
- /// 停止所有任务
- /// </summary>
- public void StopAllTask()
- {
- }
- /// <summary>
- /// 停止指定任务
- /// </summary>
- /// <param name="TID"></param>
- /// <returns></returns>
- public bool StopTask(int TID)
- {
- return true;
- }
- }
- }
|