// Remove a Server from the data structures. public void RemoveServer(ServerModel ServerToRemove, IPAddress IpAddressToRemove) { // Iterate for each process in the server and remove it from the applications listed in the applicationList of the viewModel. foreach (ProcessModel proc in ServerToRemove.TheProcesses) { ServerToRemove.RemoveProcessFromApplications(proc); // The function already iterates for all the application in the list and checks if the application has still at least a server running it. // It also takes care of raising the propertyChanged. } // Remove it from the IpConnections. if (IpConnections.Contains(IpAddressToRemove)) { System.Windows.Application.Current.Dispatcher.Invoke((Action) delegate { IpConnections.Remove(IpAddressToRemove); RaisePropertyChanged("IpConnections"); }); } // Remove it from the ServerConnectons. if (ServerConnections.Contains(ServerToRemove)) { ServerConnections.Remove(ServerToRemove); } // Check that there is the entry correspondent witht the serverIpAddress. lock (syncListOfConnectionThreads) { if (_listOfConnectionThreads != null && _currentSelectedServer != null) { if (_listOfConnectionThreads.ContainsKey(_currentSelectedServer.ServerIpAddress)) { // Abort the thread running the connection. _listOfConnectionThreads[_currentSelectedServer.ServerIpAddress].Abort(); // Remove the thread from the dictionary. _listOfConnectionThreads.Remove(_currentSelectedServer.ServerIpAddress); } } } // If there are other servers, select the first of them if (ServerConnections.Count() > 0) { // Select the first server. CurrentSelectedServer = ServerConnections.First(); CurrentSelectedIpAddress = CurrentSelectedServer.ServerIpAddress; CurrentSelectedProcess = null; TheProcessesList = CurrentSelectedServer.TheProcesses; // Update the GUI RaisePropertyChanged("TheProcessesList"); RaisePropertyChanged("CurrentSelectedIpAddress"); RaisePropertyChanged("CurrentSelectedServer"); RaisePropertyChanged("CurrentSelectedProcess"); } else { // There are no more connected servers. CurrentSelectedServer = null; CurrentSelectedProcess = null; CurrentSelectedIpAddress = null; TheProcessesList = null; RaisePropertyChanged("TheProcessesList"); } }