private void ResetMonitors_Executed(object sender, ExecutedRoutedEventArgs e) { ResetMonitors resetDialog = new ResetMonitors(Profile); resetDialog.Owner = this; bool?reset = resetDialog.ShowDialog(); if (reset.HasValue && reset.Value) { GetLoadingAdorner(); // this value comes from a dependency property that can only be // read on this thread HeliosProfile profile = Profile; // now run monitor import as another thread new System.Threading.Thread(() => { ResetMonitorsThread(resetDialog, profile); }).Start(); } }
private void ResetMonitors_Executed(object sender, ExecutedRoutedEventArgs e) { ResetMonitors resetDialog = new ResetMonitors(Profile); resetDialog.Owner = this; bool?reset = resetDialog.ShowDialog(); if (reset != null && reset == true) { HeliosProfile profile = Profile; GetLoadingAdorner(); System.Threading.Thread t = new System.Threading.Thread(delegate() { ConfigManager.UndoManager.StartBatch(); ConfigManager.LogManager.LogDebug("Reseting Monitors"); try { int i = 0; foreach (Monitor display in ConfigManager.DisplayManager.Displays) { if (i < profile.Monitors.Count) { if (resetDialog.MonitorResets[i].NewMonitor != i) { ConfigManager.LogManager.LogDebug("Removing controls for replacement from Monitor " + i); Dispatcher.Invoke(DispatcherPriority.Background, new Action(resetDialog.MonitorResets[i].RemoveControls)); } ConfigManager.LogManager.LogDebug("Reseting Monitor " + i); Dispatcher.Invoke(DispatcherPriority.Background, new Action(resetDialog.MonitorResets[i].Reset)); } else { ConfigManager.LogManager.LogDebug("Adding Monitor " + i); Monitor monitor = new Monitor(display); monitor.Name = "Monitor " + i++; ConfigManager.UndoManager.AddUndoItem(new AddMonitorUndoEvent(profile, monitor)); Dispatcher.Invoke(DispatcherPriority.Background, new Action <Monitor>(profile.Monitors.Add), monitor); } i++; } while (i < profile.Monitors.Count) { ConfigManager.LogManager.LogDebug("Removing Monitor " + i); Dispatcher.Invoke(DispatcherPriority.Background, new Action <HeliosObject>(CloseProfileItem), profile.Monitors[i]); Dispatcher.Invoke(DispatcherPriority.Background, new Action(resetDialog.MonitorResets[i].RemoveControls)); ConfigManager.UndoManager.AddUndoItem(new DeleteMonitorUndoEvent(profile, profile.Monitors[i], i)); profile.Monitors.RemoveAt(i); } foreach (MonitorResetItem item in resetDialog.MonitorResets) { ConfigManager.LogManager.LogDebug("Placeing controls for old monitor " + item.OldMonitor); Dispatcher.Invoke(DispatcherPriority.Background, new Action <Monitor>(item.PlaceControls), profile.Monitors[item.NewMonitor]); } } catch (Exception ex) { MessageBox.Show("Error encountered while reseting monitors, please contact support via forums at www.scsimulations.com", "Error"); ConfigManager.LogManager.LogError("Reset Monitors - Unhandled exception", ex); } ConfigManager.UndoManager.CloseBatch(); Dispatcher.Invoke(DispatcherPriority.Background, new Action(RemoveLoadingAdorner)); }); t.Start(); } }
private void ResetMonitors_Executed(object sender, ExecutedRoutedEventArgs e) { ResetMonitors resetDialog = new ResetMonitors(Profile); resetDialog.Owner = this; bool? reset = resetDialog.ShowDialog(); if (reset != null && reset == true) { HeliosProfile profile = Profile; GetLoadingAdorner(); System.Threading.Thread t = new System.Threading.Thread(delegate() { ConfigManager.UndoManager.StartBatch(); ConfigManager.LogManager.LogDebug("Reseting Monitors"); try { int i = 0; foreach (Monitor display in ConfigManager.DisplayManager.Displays) { if (i < profile.Monitors.Count) { if (resetDialog.MonitorResets[i].NewMonitor != i) { ConfigManager.LogManager.LogDebug("Removing controls for replacement from Monitor " + i); Dispatcher.Invoke(DispatcherPriority.Background, new Action(resetDialog.MonitorResets[i].RemoveControls)); } ConfigManager.LogManager.LogDebug("Reseting Monitor " + i); Dispatcher.Invoke(DispatcherPriority.Background, new Action(resetDialog.MonitorResets[i].Reset)); } else { ConfigManager.LogManager.LogDebug("Adding Monitor " + i); Monitor monitor = new Monitor(display); monitor.Name = "Monitor " + i++; ConfigManager.UndoManager.AddUndoItem(new AddMonitorUndoEvent(profile, monitor)); Dispatcher.Invoke(DispatcherPriority.Background, new Action<Monitor>(profile.Monitors.Add), monitor); } i++; } while (i < profile.Monitors.Count) { ConfigManager.LogManager.LogDebug("Removing Monitor " + i); Dispatcher.Invoke(DispatcherPriority.Background, new Action<HeliosObject>(CloseProfileItem), profile.Monitors[i]); Dispatcher.Invoke(DispatcherPriority.Background, new Action(resetDialog.MonitorResets[i].RemoveControls)); ConfigManager.UndoManager.AddUndoItem(new DeleteMonitorUndoEvent(profile, profile.Monitors[i], i)); profile.Monitors.RemoveAt(i); } foreach (MonitorResetItem item in resetDialog.MonitorResets) { ConfigManager.LogManager.LogDebug("Placeing controls for old monitor " + item.OldMonitor); Dispatcher.Invoke(DispatcherPriority.Background, new Action<Monitor>(item.PlaceControls), profile.Monitors[item.NewMonitor]); } } catch (Exception ex) { MessageBox.Show("Error encountered while reseting monitors, please contact support via forums at www.scsimulations.com", "Error"); ConfigManager.LogManager.LogError("Reset Monitors - Unhandled exception", ex); } ConfigManager.UndoManager.CloseBatch(); Dispatcher.Invoke(DispatcherPriority.Background, new Action(RemoveLoadingAdorner)); }); t.Start(); } }