Moved index retrieval in Invoke and corrected index sanity check. Update the combobox

and unregister item event in a try-finally block (may cure CA-289721); suspend-resume
layout when updating the datagridview.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2018-06-01 00:10:05 +01:00 committed by Mihaela Stoica
parent 3f8feb4bdd
commit b36993228c

View File

@ -273,7 +273,8 @@ namespace XenAdmin.Wizards.GenericPages
updatingDestinationCombobox = true;
ClearComboBox();
foreach (var xenConnection in ConnectionsManager.XenConnectionsCopy.Where(con => con.IsConnected).Except(ignoredConnections))
var targetConnections = ConnectionsManager.XenConnectionsCopy.Where(con => con.IsConnected).Except(ignoredConnections).ToList();
foreach (var xenConnection in targetConnections)
{
DelayLoadingOptionComboBoxItem item = null;
@ -365,6 +366,8 @@ namespace XenAdmin.Wizards.GenericPages
if (target != null)
Connection = target.Item.Connection;
m_dataGridView.SuspendLayout();
ClearDataGridView();
var hasPoolSharedStorage = HasPoolSharedStorage();
@ -427,6 +430,7 @@ namespace XenAdmin.Wizards.GenericPages
finally
{
updatingHomeServerList = false;
m_dataGridView.ResumeLayout();
}
}
@ -475,44 +479,43 @@ namespace XenAdmin.Wizards.GenericPages
if (item == null)
throw new NullReferenceException("Trying to update delay loaded reason but failed to extract reason");
Program.Invoke(Program.MainWindow, () =>
{
int index = m_comboBoxConnection.Items.IndexOf(item);
if (index > -1)
{
Program.Invoke( Program.MainWindow, delegate()
{
int selectedIndex = m_comboBoxConnection.SelectedIndex;
if (index > m_comboBoxConnection.Items.Count)
if (index < 0 || index >= m_comboBoxConnection.Items.Count)
return;
if (updatingDestinationCombobox || updatingHomeServerList)
return;
DelayLoadingOptionComboBoxItem tempItem =
m_comboBoxConnection.Items[index] as DelayLoadingOptionComboBoxItem;
int selectedIndex = m_comboBoxConnection.SelectedIndex;
var tempItem = m_comboBoxConnection.Items[index] as DelayLoadingOptionComboBoxItem;
if (tempItem == null)
throw new NullReferenceException("Trying to update delay loaded reason but failed to extract reason");
tempItem.CopyFrom(item);
try
{
m_comboBoxConnection.BeginUpdate();
m_comboBoxConnection.Items.RemoveAt(index);
if (updatingDestinationCombobox || updatingHomeServerList)
{
m_comboBoxConnection.EndUpdate();
return;
}
m_comboBoxConnection.Items.Insert(index, tempItem);
m_comboBoxConnection.SelectedIndex = selectedIndex;
m_comboBoxConnection.EndUpdate();
if (tempItem.PreferAsSelectedItem)
m_comboBoxConnection.SelectedItem = tempItem;
item.ReasonUpdated -= DelayLoadedComboBoxItem_ReasonChanged;
});
}
finally
{
m_comboBoxConnection.EndUpdate();
item.ReasonUpdated -= DelayLoadedComboBoxItem_ReasonChanged;
}
});
}
private void PropertyChanged(object sender, PropertyChangedEventArgs e)