private bool PurgePanelContext(SynchronizationContext synchronizationContext, bool _panelStatus, DataModel.Panel _Panel, string msg) { synchronizationContext.Post(new SendOrPostCallback(o => { CheckBox ck = _parentForm.splitContainerMain.Panel2.Controls["chkbx_PrugingP1"] as CheckBox; ck.Checked = true; _panelStatus = PurgePanel(_Panel.ID, msg); Thread.Sleep(3000); if (_panelStatus) { ck.BackColor = System.Drawing.Color.Red; } else { ck.BackColor = System.Drawing.Color.Teal; } ck.Checked = false; }), msg); return(_panelStatus); }
public System.Threading.Tasks.Task <bool> RunPanel(DataModel.Panel Panel, SynchronizationContext synchronizationContext) { int _port = PORT_0; bool _panelStatus = false; DataModel.Panel _Panel = Panel; System.Threading.Tasks.Task <bool> task = System.Threading.Tasks.Task.Run <bool>(() => { Console.WriteLine("Task on thread {0} started.", Thread.CurrentThread.ManagedThreadId); if (_Panel.IsActive) { switch (_Panel.Number) { case PANEL_1: _port = PORT_2; break; case PANEL_2: _port = PORT_1; break; case PANEL_3: _port = PORT_0; break; default: _port = PORT_0; break; } string msg = "Purging Panel " + _Panel.Number + " Poert " + _port; _panelStatus = PurgePanelContext(synchronizationContext, _panelStatus, _Panel, msg); synchronizationContext.Post(new SendOrPostCallback(o => { CheckBox ck = _parentForm.splitContainerMain.Panel2.Controls["chkbx_PrugingP1"] as CheckBox; if (_panelStatus) { ck.BackColor = System.Drawing.Color.Red; } else { ck.BackColor = System.Drawing.Color.Teal; } }), msg); if (_panelStatus) { Console.WriteLine("Purge Failure."); } else { Console.WriteLine("Purge Completed."); PurgeComplete(synchronizationContext, _Panel.Number); } #if DEBUG Console.WriteLine("Task on thread {0} finished.", Thread.CurrentThread.ManagedThreadId); #endif Thread.Sleep(3000); if (_panelStatus == false) { int length = 12; string msg2 = "Panel Number:" + _Panel.Number.ToString(); CalibratePanel(_Panel.Number, _panelStatus, "Calibrate Panel" + msg2); for (int i = 1; i < length; i++) { switch (i) { //case CYCLINDER_VALVE_0: // _snifferDataArray[_Panel.Number - 1, i] = new SnifferData(true, "AB12345", 1, "hcl", -0.99M, 1, 1, 20, -0.99M); //SNIFFER-SATION1 // ProcessCylinder(_port, CYCLINDER_VALVE_0, _snifferDataArray[_Panel.Number - 1, i], msg2); // break; case CYCLINDER_VALVE_1: _snifferDataArray[_Panel.Number - 1, i] = new SnifferData(true, "AB12345", 1, "hcl", -0.99M, 1, 1, 20, -0.99M); //SNIFFER-SATION1 ProcessCylinder(_port, CYCLINDER_VALVE_1, _snifferDataArray[_Panel.Number - 1, i], msg2); break; case CYCLINDER_VALVE_2: _snifferDataArray[_Panel.Number - 1, i] = new SnifferData(true, "AB12345", 1, "hcl", -0.99M, 1, 1, 20, -0.99M); //SNIFFER-SATION1 ProcessCylinder(_port, CYCLINDER_VALVE_2, _snifferDataArray[_Panel.Number - 1, i], msg2); break; case CYCLINDER_VALVE_3: ProcessCylinder(_port, CYCLINDER_VALVE_3, _snifferDataArray[_Panel.Number - 1, i], msg2); _snifferDataArray[_Panel.Number - 1, i] = new SnifferData(true, "AB12345", 1, "hcl", -0.99M, 1, 1, 20, -0.99M); //SNIFFER-SATION1 break; case CYCLINDER_VALVE_4: _snifferDataArray[_Panel.Number - 1, i] = new SnifferData(true, "AB12345", 1, "hcl", -0.99M, 1, 1, 20, -0.99M); //SNIFFER-SATION1 ProcessCylinder(_port, CYCLINDER_VALVE_4, _snifferDataArray[_Panel.Number - 1, i], msg2); break; case CYCLINDER_VALVE_5: _snifferDataArray[_Panel.Number - 1, i] = new SnifferData(true, "AB12345", 1, "hcl", -0.99M, 1, 1, 20, -0.99M); //SNIFFER-SATION1 ProcessCylinder(_port, CYCLINDER_VALVE_5, _snifferDataArray[_Panel.Number - 1, i], msg2); break; case CYCLINDER_VALVE_6: _snifferDataArray[_Panel.Number - 1, i] = new SnifferData(true, "AB12345", 1, "hcl", -0.99M, 1, 1, 20, -0.99M); //SNIFFER-SATION1 ProcessCylinder(_port, CYCLINDER_VALVE_6, _snifferDataArray[_Panel.Number - 1, i], msg2); break; case CYCLINDER_VALVE_7: _snifferDataArray[_Panel.Number - 1, i] = new SnifferData(true, "AB12345", 1, "hcl", -0.99M, 1, 1, 20, -0.99M); //SNIFFER-SATION1 ProcessCylinder(_port, CYCLINDER_VALVE_7, _snifferDataArray[_Panel.Number - 1, i], msg2); break; case CYCLINDER_VALVE_8: _snifferDataArray[_Panel.Number - 1, i] = new SnifferData(true, "AB12345", 1, "hcl", -0.99M, 1, 1, 20, -0.99M); //SNIFFER-SATION1 ProcessCylinder(_port, CYCLINDER_VALVE_8, _snifferDataArray[_Panel.Number - 1, i], msg2); break; case CYCLINDER_VALVE_9: _snifferDataArray[_Panel.Number - 1, i] = new SnifferData(true, "AB12345", 1, "hcl", -0.99M, 1, 1, 20, -0.99M); //SNIFFER-SATION1 ProcessCylinder(_port, CYCLINDER_VALVE_9, _snifferDataArray[_Panel.Number - 1, i], msg2); break; case CYCLINDER_VALVE_10: ProcessCylinder(_port, CYCLINDER_VALVE_10, _snifferDataArray[_Panel.Number - 1, i], msg2); _snifferDataArray[_Panel.Number - 1, i] = new SnifferData(true, "AB12345", 1, "hcl", -0.99M, 1, 1, 20, -0.99M); //SNIFFER-SATION1 break; case CYCLINDER_VALVE_11: _snifferDataArray[_Panel.Number - 1, i] = new SnifferData(true, "AB12345", 1, "hcl", -0.99M, 1, 1, 20, -0.99M); //SNIFFER-SATION1 ProcessCylinder(_port, CYCLINDER_VALVE_11, _snifferDataArray[_Panel.Number - 1, i], msg2); break; case CYCLINDER_VALVE_12: _snifferDataArray[_Panel.Number - 1, i] = new SnifferData(true, "AB12345", 1, "hcl", -0.99M, 1, 1, 20, -0.99M); //SNIFFER-SATION1 ProcessCylinder(_port, CYCLINDER_VALVE_12, _snifferDataArray[_Panel.Number - 1, i], msg2); break; //case CYCLINDER_VALVE_13: // _snifferDataArray[_Panel.Number - 1, i] = new SnifferData(true, "AB12345", 1, "hcl", -0.99M, 1, 1, 20, -0.99M); //SNIFFER-SATION1 // ProcessCylinder(_port, CYCLINDER_VALVE_13, _snifferDataArray[_Panel.Number - 1, i], msg2); // break; //case CYCLINDER_VALVE_14: // _snifferDataArray[_Panel.Number - 1, i] = new SnifferData(true, "AB12345", 1, "hcl", -0.99M, 1, 1, 20, -0.99M); //SNIFFER-SATION1 // ProcessCylinder(_port, CYCLINDER_VALVE_14, _snifferDataArray[_Panel.Number - 1, i], msg2); // break; default: break; } } } } return(true); }); return(task); }