CA-286882: Shutting down large number of VMs causes XenCenter to hang

Created a new base class for the Notifications pages (Alerts, Updates, Events). This can be used in the future to host more of the common code between these pages. For now, it implements a common mechanism for showing/hiding the page and ensures that the event handlers are deregistered when the page is hidden (i.e. when the user switches to a different view) and registered again when the page becomes visible

Signed-off-by: Mihaela Stoica <mihaela.stoica@citrix.com>
This commit is contained in:
Mihaela Stoica 2018-08-10 09:38:55 +01:00 committed by Konstantina Chremmou
parent f4d92da5ee
commit 8230315f76
9 changed files with 150 additions and 38 deletions

View File

@ -3028,21 +3028,26 @@ namespace XenAdmin
private void navigationPane_NotificationsSubModeChanged(NotificationsSubModeItem submodeItem)
{
alertPage.Visible = submodeItem.SubMode == NotificationsSubMode.Alerts;
updatesPage.Visible = submodeItem.SubMode == NotificationsSubMode.Updates;
eventsPage.Visible = submodeItem.SubMode == NotificationsSubMode.Events;
TheTabControl.Visible = false;
if (alertPage.Visible)
alertPage.RefreshAlertList();
if (updatesPage.Visible)
updatesPage.RefreshUpdateList();
if (eventsPage.Visible)
switch (submodeItem.SubMode)
{
eventsPage.RefreshDisplayedEvents();
}
case NotificationsSubMode.Alerts:
alertPage.ShowPage();
updatesPage.HidePage();
eventsPage.HidePage();
break;
case NotificationsSubMode.Updates:
alertPage.HidePage();
updatesPage.ShowPage();
eventsPage.HidePage();
break;
case NotificationsSubMode.Events:
alertPage.HidePage();
updatesPage.HidePage();
eventsPage.ShowPage();
break;
}
TheTabControl.Visible = false;
loggedInLabel1.Connection = null;
TitleLabel.Text = submodeItem.Text;
@ -3060,7 +3065,12 @@ namespace XenAdmin
{
bool tabControlWasVisible = TheTabControl.Visible;
TheTabControl.Visible = true;
alertPage.Visible = updatesPage.Visible = eventsPage.Visible = false;
if (alertPage.Visible)
alertPage.HidePage();
if (updatesPage.Visible)
updatesPage.HidePage();
if (eventsPage.Visible)
eventsPage.HidePage();
// force an update of the selected tab when switching back from Notification view,
// as some tabs ignore the update events when not visible (e.g. Snapshots, HA)

View File

@ -15,7 +15,7 @@ namespace XenAdmin.TabPages
{
if (disposing)
{
XenAdmin.Alerts.Alert.DeregisterAlertCollectionChanged(m_alertCollectionChangedWithInvoke);
DeregisterEventHandlers();
if (components != null)
components.Dispose();

View File

@ -49,7 +49,7 @@ using System.IO;
namespace XenAdmin.TabPages
{
public partial class AlertSummaryPage : UserControl
public partial class AlertSummaryPage : NotificationsBasePage
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
@ -69,18 +69,29 @@ namespace XenAdmin.TabPages
UpdateActionEnablement();
m_alertCollectionChangedWithInvoke = Program.ProgramInvokeHandler(AlertsCollectionChanged);
Alert.RegisterAlertCollectionChanged(m_alertCollectionChangedWithInvoke);
toolStripSplitButtonDismiss.DefaultItem = tsmiDismissAll;
toolStripSplitButtonDismiss.Text = tsmiDismissAll.Text;
}
public void RefreshAlertList()
#region NotificationPage overrides
protected override void RefreshPage()
{
toolStripDropDownButtonServerFilter.InitializeHostList();
toolStripDropDownButtonServerFilter.BuildFilterList();
Rebuild();
}
protected override void RegisterEventHandlers()
{
Alert.RegisterAlertCollectionChanged(m_alertCollectionChangedWithInvoke);
}
protected override void DeregisterEventHandlers()
{
Alert.DeregisterAlertCollectionChanged(m_alertCollectionChangedWithInvoke);
}
#endregion
private void SetFilterLabel()
{

View File

@ -13,7 +13,7 @@ namespace XenAdmin.TabPages
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
ConnectionsManager.History.CollectionChanged -= History_CollectionChanged;
DeregisterEventHandlers();
XenAdmin.Actions.ActionBase.NewAction -= Action_NewAction;
if (disposing && (components != null))

View File

@ -34,7 +34,6 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using XenAdmin.Actions;
@ -46,7 +45,7 @@ using XenAPI;
namespace XenAdmin.TabPages
{
public partial class HistoryPage : UserControl
public partial class HistoryPage : NotificationsBasePage
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
@ -63,17 +62,31 @@ namespace XenAdmin.TabPages
toolStripSplitButtonDismiss.DefaultItem = tsmiDismissAll;
toolStripSplitButtonDismiss.Text = tsmiDismissAll.Text;
UpdateButtons();
ConnectionsManager.History.CollectionChanged += History_CollectionChanged;
ActionBase.NewAction += Action_NewAction;
}
public void RefreshDisplayedEvents()
#region NotificationPage overrides
protected override void RefreshPage()
{
toolStripDdbFilterLocation.InitializeHostList();
toolStripDdbFilterLocation.BuildFilterList();
BuildRowList();
}
protected override void RegisterEventHandlers()
{
ConnectionsManager.History.CollectionChanged += History_CollectionChanged;
}
protected override void DeregisterEventHandlers()
{
ConnectionsManager.History.CollectionChanged -= History_CollectionChanged;
foreach (var action in ConnectionsManager.History)
DeregisterActionEvents(action);
}
#endregion
private void Action_NewAction(ActionBase action)
{
if (action == null)
@ -260,16 +273,20 @@ namespace XenAdmin.TabPages
private void RegisterActionEvents(ActionBase action)
{
action.Changed -= action_Changed;
action.Completed -= action_Changed;
DeregisterActionEvents(action);
action.Changed += action_Changed;
action.Completed += action_Changed;
}
private void RemoveActionRow(ActionBase action)
private void DeregisterActionEvents(ActionBase action)
{
action.Changed -= action_Changed;
action.Completed -= action_Changed;
}
private void RemoveActionRow(ActionBase action)
{
DeregisterActionEvents(action);
var row = FindRowFromAction(action);
if (row != null)

View File

@ -15,10 +15,7 @@
{
if (disposing)
{
XenAdmin.Core.Updates.DeregisterCollectionChanged(m_updateCollectionChangedWithInvoke);
XenAdmin.Core.Updates.RestoreDismissedUpdatesStarted -= Updates_RestoreDismissedUpdatesStarted;
XenAdmin.Core.Updates.CheckForUpdatesStarted -= CheckForUpdates_CheckForUpdatesStarted;
XenAdmin.Core.Updates.CheckForUpdatesCompleted -= CheckForUpdates_CheckForUpdatesCompleted;
DeregisterEventHandlers();
if (components != null)
components.Dispose();

View File

@ -54,7 +54,7 @@ using Timer = System.Windows.Forms.Timer;
namespace XenAdmin.TabPages
{
public partial class ManageUpdatesPage : UserControl
public partial class ManageUpdatesPage : NotificationsBasePage
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
@ -78,22 +78,36 @@ namespace XenAdmin.TabPages
UpdateButtonEnablement();
informationLabel.Click += informationLabel_Click;
m_updateCollectionChangedWithInvoke = Program.ProgramInvokeHandler(UpdatesCollectionChanged);
Updates.RegisterCollectionChanged(m_updateCollectionChangedWithInvoke);
Updates.RestoreDismissedUpdatesStarted += Updates_RestoreDismissedUpdatesStarted;
Updates.CheckForUpdatesStarted += CheckForUpdates_CheckForUpdatesStarted;
Updates.CheckForUpdatesCompleted += CheckForUpdates_CheckForUpdatesCompleted;
toolStripSplitButtonDismiss.DefaultItem = dismissAllToolStripMenuItem;
toolStripSplitButtonDismiss.Text = dismissAllToolStripMenuItem.Text;
toolStripButtonUpdate.Visible = false;
}
public void RefreshUpdateList()
#region NotificationPage overrides
protected override void RefreshPage()
{
toolStripDropDownButtonServerFilter.InitializeHostList();
toolStripDropDownButtonServerFilter.BuildFilterList();
Rebuild();
Rebuild();
}
protected override void RegisterEventHandlers()
{
Updates.RegisterCollectionChanged(m_updateCollectionChangedWithInvoke);
Updates.RestoreDismissedUpdatesStarted += Updates_RestoreDismissedUpdatesStarted;
Updates.CheckForUpdatesStarted += CheckForUpdates_CheckForUpdatesStarted;
Updates.CheckForUpdatesCompleted += CheckForUpdates_CheckForUpdatesCompleted;
}
protected override void DeregisterEventHandlers()
{
Updates.DeregisterCollectionChanged(m_updateCollectionChangedWithInvoke);
Updates.RestoreDismissedUpdatesStarted -= Updates_RestoreDismissedUpdatesStarted;
Updates.CheckForUpdatesStarted -= CheckForUpdates_CheckForUpdatesStarted;
Updates.CheckForUpdatesCompleted -= CheckForUpdates_CheckForUpdatesCompleted;
}
#endregion
private void UpdatesCollectionChanged(object sender, CollectionChangeEventArgs e)
{
Program.AssertOnEventThread();

View File

@ -0,0 +1,60 @@
/* Copyright (c) Citrix Systems, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms,
* with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
using System.Windows.Forms;
namespace XenAdmin.TabPages
{
public class NotificationsBasePage: UserControl
{
protected virtual void RefreshPage()
{ }
protected virtual void RegisterEventHandlers()
{ }
protected virtual void DeregisterEventHandlers()
{ }
public void ShowPage()
{
Visible = true;
RefreshPage();
RegisterEventHandlers();
}
public void HidePage()
{
Visible = false;
DeregisterEventHandlers();
}
}
}

View File

@ -451,6 +451,9 @@
<Compile Include="TabPages\HomePage.Designer.cs">
<DependentUpon>HomePage.cs</DependentUpon>
</Compile>
<Compile Include="TabPages\NotificationsBasePage.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="TabPages\PvsPage.cs">
<SubType>UserControl</SubType>
</Compile>