//2020.07.14 Hsinyu Chang: doCheckIPLinkStatus的平行迴圈改寫 //因 1)foreach中的每個元素沒有資料相依 // 2)ping為I/O bound,用sequential loop會有大部分時間在空等 // 3)ping結果有時效性 //Note: 目前作法要等到parallel foreach的每個元素都ping完才會更新資料,尚有優化空間 private void doCheckIPLinkStatusParallel() { if (System.Threading.Interlocked.Exchange(ref syncCheckIP_Point, 1) == 0) { try { Parallel.ForEach(dicCommInfo, keyPair => { CommuncationInfo Info = keyPair.Value; if (!SCUtility.isEmpty(Info.Getway_IP)) { Info.IsCommunactionSuccess = PingIt(Info.Getway_IP); } if (!SCUtility.isEmpty(Info.Remote_IP)) { Info.IsConnectinoSuccess = PingIt(Info.Remote_IP); } }); line.setConnectionInfo(dicCommInfo); } catch (Exception ex) { logger.Error(ex, "Exception"); } finally { System.Threading.Interlocked.Exchange(ref syncCheckIP_Point, 0); } } }
public void start(BCMainForm _form) { form = _form; dicCommInfo = form.BCApp.SCApplication.getEQObjCacheManager().CommonInfo.dicCommunactionInfo; tlp_LightBase.RowStyles.Clear(); tlp_LightBase.RowStyles.Add(new RowStyle(SizeType.Absolute, 50)); foreach (KeyValuePair <string, CommuncationInfo> keyValue in dicCommInfo) { CommuncationInfo info = keyValue.Value; creatTlpRow(info); } }
public void refresh() { foreach (KeyValuePair <string, PictureBox[]> keyValue in dicCommInfoPicture) { if (!dicCommInfo.ContainsKey(keyValue.Key)) { continue; } CommuncationInfo info = dicCommInfo[keyValue.Key]; PictureBox[] CommAndConnInfo = keyValue.Value; CommAndConnInfo[0].Image = info.IsCommunactionSuccess ? Pic_Ball_Green : Pic_Ball_Rad; CommAndConnInfo[1].Image = info.IsConnectinoSuccess ? Pic_Ball_Green : Pic_Ball_Rad; } }
private void creatTlpRow(CommuncationInfo info) { Label name = new Label() { Text = info.Name, Anchor = AnchorStyles.None }; name.Dock = DockStyle.Fill; name.TextAlign = ContentAlignment.MiddleCenter; PictureBox pic_comm = new PictureBox(); pic_comm.Image = info.IsCommunactionSuccess ? Pic_Ball_Green : Pic_Ball_Rad; pic_comm.SizeMode = PictureBoxSizeMode.Zoom; PictureBox pic_conn = new PictureBox(); pic_conn.Image = info.IsConnectinoSuccess ? Pic_Ball_Green : Pic_Ball_Rad; pic_conn.SizeMode = PictureBoxSizeMode.Zoom; tlp_LightBase.Controls.Add(name, 0, tlp_LightBase.RowCount - 1); tlp_LightBase.Controls.Add(pic_comm, 1, tlp_LightBase.RowCount - 1); tlp_LightBase.Controls.Add(pic_conn, 2, tlp_LightBase.RowCount - 1); tlp_LightBase.RowCount++; tlp_LightBase.RowStyles.Add(new RowStyle(SizeType.Absolute, 50)); dicCommInfoPicture.Add(info.Name, new PictureBox[] { pic_comm, pic_conn }); //info.addEventHandler(event_id // , BCFUtility.getPropertyName(() => info.IsCommunactionSuccess) // , (s1, e1) => // { // bool isSuccess = (bool)e1.PropertyValue; // pic_comm.Image = isSuccess ? Pic_Ball_Green : Pic_Ball_Rad; // }); //info.addEventHandler(event_id // , BCFUtility.getPropertyName(() => info.IsConnectinoSuccess) // , (s1, e1) => // { // bool isSuccess = (bool)e1.PropertyValue; // pic_conn.Image = isSuccess ? Pic_Ball_Green : Pic_Ball_Rad; // }); }
public void setConnectionInfo(Dictionary <string, CommuncationInfo> dicCommInfo) { foreach (KeyValuePair <string, CommuncationInfo> keyPair in dicCommInfo) { CommuncationInfo Info = keyPair.Value; switch (keyPair.Key) { case "MCS": MCSConnectionSuccess = Info.IsConnectinoSuccess; break; case "ROUTER": RouterConnectionSuccess = Info.IsConnectinoSuccess; break; case "AGV_1": AGV1ConnectionSuccess = Info.IsConnectinoSuccess; break; case "AGV_2": AGV2ConnectionSuccess = Info.IsConnectinoSuccess; break; case "AGV_3": AGV3ConnectionSuccess = Info.IsConnectinoSuccess; break; case "AGV_4": AGV4ConnectionSuccess = Info.IsConnectinoSuccess; break; case "AGV_5": AGV5ConnectionSuccess = Info.IsConnectinoSuccess; break; case "AGV_6": AGV6ConnectionSuccess = Info.IsConnectinoSuccess; break; case "AGV_7": AGV7ConnectionSuccess = Info.IsConnectinoSuccess; break; case "AGV_8": AGV8ConnectionSuccess = Info.IsConnectinoSuccess; break; case "AGV_9": AGV9ConnectionSuccess = Info.IsConnectinoSuccess; break; case "AGV_10": AGV10ConnectionSuccess = Info.IsConnectinoSuccess; break; case "AGV_11": AGV11ConnectionSuccess = Info.IsConnectinoSuccess; break; case "AGV_12": AGV12ConnectionSuccess = Info.IsConnectinoSuccess; break; case "AGV_13": AGV13ConnectionSuccess = Info.IsConnectinoSuccess; break; case "AGV_14": AGV14ConnectionSuccess = Info.IsConnectinoSuccess; break; break; case "CHARGER_PLC": ChargePLCConnectionSuccess = Info.IsConnectinoSuccess; break; case "ADAM_1": ADAM1ConnectionSuccess = Info.IsConnectinoSuccess; break; case "ADAM_2": ADAM2ConnectionSuccess = Info.IsConnectinoSuccess; break; case "ADAM_3": ADAM3ConnectionSuccess = Info.IsConnectinoSuccess; break; case "ADAM_4": ADAM4ConnectionSuccess = Info.IsConnectinoSuccess; break; case "ADAM_5": ADAM5ConnectionSuccess = Info.IsConnectinoSuccess; break; case "AP1": AP1ConnectionSuccess = Info.IsConnectinoSuccess; break; case "AP2": AP2ConnectionSuccess = Info.IsConnectinoSuccess; break; case "AP3": AP3ConnectionSuccess = Info.IsConnectinoSuccess; break; case "AP4": AP4ConnectionSuccess = Info.IsConnectinoSuccess; break; case "AP5": AP5ConnectionSuccess = Info.IsConnectinoSuccess; break; case "AP6": AP6ConnectionSuccess = Info.IsConnectinoSuccess; break; case "AP7": AP7ConnectionSuccess = Info.IsConnectinoSuccess; break; case "AP8": AP8ConnectionSuccess = Info.IsConnectinoSuccess; break; case "AP9": AP9ConnectionSuccess = Info.IsConnectinoSuccess; break; case "AP10": AP10ConnectionSuccess = Info.IsConnectinoSuccess; break; } } }