Browse Source

添加线程操作类

章政 7 years ago
parent
commit
6f35169f43

+ 24 - 0
UAS_DeviceMonitor/Main.cs

@@ -9,6 +9,7 @@ using UAS_DeviceMonitor.PublicMethod;
 using DevExpress.XtraEditors;
 using DevExpress.XtraGrid;
 using DevExpress.XtraGrid.Views.Grid;
+using System.Threading;
 
 namespace UAS_DeviceMonitor
 {
@@ -167,7 +168,28 @@ namespace UAS_DeviceMonitor
         #region PagePollingSetting业务代码
         private void ButtonStartPolling_Click(object sender, EventArgs e)
         {
+            PollingTask pt = new PollingTask();
+            pt.AddTask(RunTask);
+            pt.AddTask(RunTask1);
+            pt.AddTask(RunTask2);
+            pt.StartAllTask();
+        }
+
+        private void RunTask(object i)
+        {
+            Thread.Sleep(1 * 1000);
+            Console.WriteLine(1);
+        }
 
+        private void RunTask1(object i)
+        {
+            Thread.Sleep(2 * 1000);
+            Console.WriteLine(3);
+        }
+        private void RunTask2(object i)
+        {
+            Thread.Sleep(3 * 1000);
+            Console.WriteLine(3);
         }
 
         private void ButtonPausePolling_Click(object sender, EventArgs e)
@@ -175,6 +197,8 @@ namespace UAS_DeviceMonitor
 
         }
 
+        
+
         /// <summary>
         /// 设置GridView下拉框的值
         /// </summary>

+ 122 - 0
UAS_DeviceMonitor/PublicMethod/PollingTask.cs

@@ -0,0 +1,122 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace UAS_DeviceMonitor.PublicMethod
+{
+    class PollingTask
+    {
+
+        List<Task> list = new List<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)
+        {
+            Task task1 = new Task(action);
+            list.Add(task1);
+        }
+
+        /// <summary>
+        /// 添加任务,默认添加后自动执行,返回创建的TASK的ID
+        /// </summary>
+        /// <param name="TCode"></param>
+        /// <returns></returns>
+        public void AddTask(Action<object> action)
+        {
+            Task task1 = new Task(action, new object());
+            list.Add(task1);
+        }
+
+
+        /// <summary>
+        /// 添加一系列任务
+        /// </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()
+        {
+            return true;
+        }
+
+        /// <summary>
+        /// 暂停任务
+        /// </summary>
+        /// <param name="TID"></param>
+        /// <returns></returns>
+        public bool PauseTask(int TID)
+        {
+            return true;
+        }
+
+        /// <summary>
+        /// 开启所有任务
+        /// </summary>
+        public void StartAllTask()
+        {
+            for (int i = 0; i < list.Count; i++)
+            {
+                list[i].Start();
+                list[i].Wait();
+            }
+        }
+
+        /// <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;
+        }
+    }
+}

+ 0 - 11
UAS_DeviceMonitor/PublicMethod/PollingThread.cs

@@ -1,11 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace UAS_DeviceMonitor.PublicMethod
-{
-    class PollingThread
-    {
-    }
-}

+ 1 - 1
UAS_DeviceMonitor/UAS_DeviceMonitor.csproj

@@ -116,7 +116,7 @@
     <Compile Include="PublicMethod\BaseUtil.cs" />
     <Compile Include="PublicMethod\LogManager.cs" />
     <Compile Include="PublicMethod\ModeBusTCPServer.cs" />
-    <Compile Include="PublicMethod\PollingThread.cs" />
+    <Compile Include="PublicMethod\PollingTask.cs" />
     <EmbeddedResource Include="CustomerControl\AutoDataGridControl\AutoDataGridControl.resx">
       <DependentUpon>AutoDataGridControl.cs</DependentUpon>
     </EmbeddedResource>