private void ComDeviceInfoManager_AddedDevicesAsync(object sender, ComDeviceInfoManagerEventArgs e) { List <string> devices = new List <string>(); foreach (var item in e.ComDevices) { ComReader comReader = new ComReader(item.Port); if (comReader.Open()) { IcpDeviceManager IcpDeviceManager = new IcpDeviceManager(comReader); IcpDeviceManagers.Add(IcpDeviceManager); } } ScanIcpDevices(devices).ContinueWith(delegate { AddedDevicesCallback(devices.ToArray()); }); //ScanIcpDevices(devices). //ComDevicesAdded?.Invoke(this, new ComDeviceControllerEventArgs(devices.ToArray())); }
private void ComDeviceInfoManager_RemovedDevices(object sender, ComDeviceInfoManagerEventArgs e) { List <string> devices = new List <string>(); foreach (var item in e.ComDevices) { var res = IcpDeviceManagers.FindAll(dev => dev.GetComPort() == item.Port); IcpDeviceManagers.RemoveAll(dev => dev.GetComPort() == item.Port); TaskEx.Run(() => { foreach (var it in res) { it.CloseConnection(); foreach (var i in it.IcpDeviceDict) { devices.Add(i.Value.Name); } } }).ContinueWith(delegate { RemovedDevicesCallback(devices.ToArray()); }); } //ComDevicesRemoved?.Invoke(this, new ComDeviceControllerEventArgs(devices.ToArray())); }