|
@@ -27,14 +27,20 @@ namespace parkMonitor.server.CoreThread
|
|
|
//
|
|
|
DBLocationOperator locationOper;
|
|
|
DBOperation oper;
|
|
|
+ int localGarageId = 0;
|
|
|
|
|
|
string[] equipNames = new string[] { EquipmentName.PLC, EquipmentName.NumMachine, EquipmentName.Web, EquipmentName.Queue };
|
|
|
|
|
|
public CoreThreadTest2()
|
|
|
{
|
|
|
- equipmentStatus_address = Convert.ToInt32(ConfigurationManager.AppSettings["equipmentStatus_address"]);
|
|
|
- locationOper = new DBLocationOperator();
|
|
|
- oper = new DBOperation();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ equipmentStatus_address = Convert.ToInt32(ConfigurationManager.AppSettings["equipmentStatus_address"]);
|
|
|
+ localGarageId = Convert.ToInt32(ConfigurationManager.AppSettings["localGarageId"]);
|
|
|
+ locationOper = new DBLocationOperator();
|
|
|
+ oper = new DBOperation();
|
|
|
+ }
|
|
|
+ catch (Exception) { }
|
|
|
}
|
|
|
|
|
|
public void Start()
|
|
@@ -88,34 +94,42 @@ namespace parkMonitor.server.CoreThread
|
|
|
|
|
|
public void BeginWorking()
|
|
|
{
|
|
|
- while (true)
|
|
|
+ Task.Factory.StartNew(() =>
|
|
|
{
|
|
|
- Func<AbstractMessage> func = new Func<AbstractMessage>(GetExecuteNumberPlate);
|
|
|
-
|
|
|
- TaskFactory taskFactory = new TaskFactory();
|
|
|
- List<Task> tasklist = new List<Task>();
|
|
|
- IAsyncResult result = func.BeginInvoke(null, null);
|
|
|
- Action act1 = new Action(() =>
|
|
|
+ while (true)
|
|
|
{
|
|
|
- GetTotalStatus();
|
|
|
- });
|
|
|
- tasklist.Add(taskFactory.StartNew(act1));
|
|
|
- Task.WaitAll(tasklist.ToArray());
|
|
|
- Command queueCmd = (Command)func.EndInvoke(result);
|
|
|
- Task.Factory.StartNew(() =>
|
|
|
- {
|
|
|
- SimpleCMDFactory simpleCMDFactory = new SimpleCMDFactory();
|
|
|
- AbstractCmd abstractCmd = simpleCMDFactory.createCmd(queueCmd);
|
|
|
- abstractCmd.executeCmd(queueCmd);
|
|
|
- });
|
|
|
- //同步数据库
|
|
|
- Task.Factory.StartNew(() =>
|
|
|
+ Func<AbstractMessage> func = new Func<AbstractMessage>(GetExecuteNumberPlate);
|
|
|
+
|
|
|
+ TaskFactory taskFactory = new TaskFactory();
|
|
|
+ List<Task> tasklist = new List<Task>();
|
|
|
+ IAsyncResult result = func.BeginInvoke(null, null);
|
|
|
+ Action act1 = new Action(() =>
|
|
|
+ {
|
|
|
+ GetTotalStatus();
|
|
|
+ });
|
|
|
+ tasklist.Add(taskFactory.StartNew(act1));
|
|
|
+ Task.WaitAll(tasklist.ToArray());
|
|
|
+ Command queueCmd = (Command)func.EndInvoke(result);
|
|
|
+ Task.Factory.StartNew(() =>
|
|
|
+ {
|
|
|
+ SimpleCMDFactory simpleCMDFactory = new SimpleCMDFactory();
|
|
|
+ AbstractCmd abstractCmd = simpleCMDFactory.createCmd(queueCmd);
|
|
|
+ abstractCmd.executeCmd(queueCmd);
|
|
|
+ });
|
|
|
+ Thread.Sleep(100);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //同步数据库
|
|
|
+ Task.Factory.StartNew(() =>
|
|
|
+ {
|
|
|
+ while (true)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
//更新车库表车位数
|
|
|
- int freeSpaceCount = locationOper.getGarageFreeSpace(queueCmd.garageID);
|
|
|
- oper.UpdateGarageFreeSpace(freeSpaceCount, queueCmd.garageID);
|
|
|
+ int freeSpaceCount = locationOper.getGarageFreeSpace(localGarageId);
|
|
|
+ oper.UpdateGarageFreeSpace(freeSpaceCount, localGarageId);
|
|
|
//更新车位状态
|
|
|
int[] spaceID = locationOper.GetAllParkingSpaceID();
|
|
|
if (spaceID != null)
|
|
@@ -130,10 +144,9 @@ namespace parkMonitor.server.CoreThread
|
|
|
{
|
|
|
Console.WriteLine("无同步数据");
|
|
|
}
|
|
|
- Thread.Sleep(1800000);
|
|
|
- });
|
|
|
- Thread.Sleep(100);
|
|
|
- }
|
|
|
+ Thread.Sleep(8000);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/// <summary>挂起</summary>
|