private void sendCommandWorkThread() { while (true) { Thread.Sleep(1000); List <string> nowOnline = new List <string>(); nowOnline.AddRange(onlineLabel); foreach (string module in nowOnline) { if (handles.ContainsKey(module)) { Dictionary <string, uint> handle = handles[module]; uint DO1 = handle["DO1"]; uint DO2 = handle["DO2"]; uint DO3 = handle["DO3"]; uint DO4 = handle["DO4"]; uint DO5 = handle["DO5"]; uint DO6 = handle["DO6"]; object value1 = null; object value2 = null; object value3 = null; object value4 = null; object value5 = null; object value6 = null; try { OPClib.ReadTag(DO1, ref value1); OPClib.ReadTag(DO2, ref value2); OPClib.ReadTag(DO3, ref value3); OPClib.ReadTag(DO4, ref value4); OPClib.ReadTag(DO5, ref value5); OPClib.ReadTag(DO6, ref value6); } catch (Exception ex) { continue; } Dictionary <string, object> values = new Dictionary <string, object>(); values.Add("DO1", value1); values.Add("DO2", value2); values.Add("DO3", value3); values.Add("DO4", value4); values.Add("DO5", value5); values.Add("DO6", value6); if (!currentOutputValue.ContainsKey(module)) { currentOutputValue.Add(module, values); } else { Dictionary <string, object> savedValue = currentOutputValue[module]; if (!compareOutputValues(savedValue, values)) { try { listener.Send(constructDataPacket(values, module)); currentOutputValue[module] = values; } catch (Exception ex) { continue; } } } } } } }