private void SyncOSDConfig(DeviceModel deviceModel) { this.MainGridEnabled = false; try { OSDConfig osd = NetworkDeviceHelper.GetOSDConfig(deviceModel); int currentCount = 0; int maxCount = 100; DeviceModel[] selectedDevices = this.Devices.Where(x => x.IsSelected == true).ToArray(); foreach (var item in selectedDevices) { do { if (currentCount < maxCount) { Interlocked.Increment(ref currentCount); Task task = Task.Run(() => { CopyOSDConfig(item, osd); }) .ContinueWith(x => { Interlocked.Decrement(ref currentCount); }); break; } System.Threading.Thread.Sleep(100); } while (true); } while (currentCount > 0) { System.Threading.Thread.Sleep(100); } this.ShowMessageAsync("同步OSD参数完成", null); } catch (Exception ex) { this.ShowMessageAsync("同步OSD参数失败", ex.Message.ToString()); Helper.Logger.Error(String.Format("SyncOSDConfig {0} error.", deviceModel?.IPAddress), ex); } finally { this.MainGridEnabled = true; } }
private void ReadOSDName(Object state) { DeviceModel model = state as DeviceModel; Int32 retryTimes = 0; while (retryTimes++ < 3) { try { if (model == null) { return; } model.Name = NetworkDeviceHelper.GetOSDConfig(model).Name; break; } catch (Exception ex) { System.Threading.Thread.Sleep(2000); Helper.Logger.Error(String.Format("ReadOSDName failed, IPAddress:{0}.", model?.IPAddress), ex); } } }