DeviceRunControl.cs
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using OnlineStore;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DeviceLibrary
{
public class DeviceRunControl
{
public static List<ManualResetEvent> manualResets = new List<ManualResetEvent>();
List<IDevice> DevicesList;
string DeviceListName;
ManualResetEvent resetEvent = new ManualResetEvent(false);
public DeviceRunControl(string name, List<IDevice> device) {
DevicesList = device;
DeviceListName = name;
manualResets.Add(resetEvent);
LogUtil.info($"{DeviceListName}导入设备{DevicesList.Count}个");
}
Thread thread;
public void Start() {
thread = new Thread(new ThreadStart(Run));
thread.Start();
resetEvent.Reset();
}
void Run() {
LogUtil.info($"{DeviceListName}设备线程启动");
while (RobotManage.mainMachine.mstart)
{
Thread.Sleep(200);
ManualResetEvent.WaitAll(new ManualResetEvent[] { RobotManage.mainMachine.ResetEvent });
if (!RobotManage.mainMachine.canRunning || !RobotManage.mainMachine.mstart)
continue;
DevicesList.ForEach(x =>
{
try
{
x.Process();
}
catch (Exception ex)
{
MsgService.MSList[x.GroupName].add(ex.ToString(), MsgLevel.warning);
MsgService.MSList[x.GroupName].setlogones();
}
finally
{
MsgService.MSList[x.GroupName].Show();
}
});
//ProcessMoveinfoEvent?.Invoke(MoveInfo.List);
if (!RobotManage.mainMachine.UserPause && RobotManage.mainMachine.mstart)
{
DevicesList.ForEach(x =>
{
MsgService.MSList[x.GroupName].clear();
});
}
resetEvent.Set();
}
LogUtil.info($"{DeviceListName}设备线程已退出.");
}
}
}