public void RemoveProcessFromApplications(ProcessModel process) { bool appHasToBeRemoved = false; string exeName = Path.GetFileName(process.ExePath); // returns File.exe ApplicationModel applic = null; // Search for the application. foreach (ApplicationModel app in _mainWinWMCaller.TheApplicationsList) { if (app.ApplicationName.Equals(exeName)) { // Remove this server from its list. app.AppServerList.Remove(this); if (app.AppServerList.Count() == 0) { appHasToBeRemoved = true; applic = app; } break; } } _mainWinWMCaller.RaisePropertyChanged("ServerOfCurrentApplicationList"); _mainWinWMCaller.RaisePropertyChanged("Applications"); // Check if this application has to be removed. if (appHasToBeRemoved) { // Check that the application that has to be removed is not the selected one if (applic.Equals(_mainWinWMCaller.CurrentSelectedApplication)) { // Deselect the application _mainWinWMCaller.CurrentSelectedApplication = null; _mainWinWMCaller.ServerOfCurrentApplicationList.Clear(); _mainWinWMCaller.SelectedServersForApplication.Clear(); } System.Windows.Application.Current.Dispatcher.Invoke((Action) delegate { _mainWinWMCaller.TheApplicationsList.Remove(applic); }); // Update the GUI _mainWinWMCaller.RaisePropertyChanged("Applications"); _mainWinWMCaller.RaisePropertyChanged("CurrentSelectedApplication"); _mainWinWMCaller.RaisePropertyChanged("ServerOfCurrentApplicationList"); _mainWinWMCaller.RaisePropertyChanged("SelectedServersForApplication"); } }