diff --git a/XenAdmin/MainWindow.Designer.cs b/XenAdmin/MainWindow.Designer.cs index f33d8e115..e6959b7bc 100644 --- a/XenAdmin/MainWindow.Designer.cs +++ b/XenAdmin/MainWindow.Designer.cs @@ -15,24 +15,17 @@ namespace XenAdmin { Program.Exiting = true; - XenAdmin.Core.Clip.UnregisterClipboardViewer(); - pluginManager.PluginsChanged -= pluginManager_PluginsChanged; - pluginManager.Dispose(); + UnRegisterEvents(); - OtherConfigAndTagsWatcher.DeregisterEventHandlers(); - ConnectionsManager.History.CollectionChanged -= History_CollectionChanged; - XenAdmin.Alerts.Alert.DeregisterAlertCollectionChanged(XenCenterAlerts_CollectionChanged); - XenAdmin.Core.Updates.DeregisterCollectionChanged(Updates_CollectionChanged); - ConnectionsManager.XenConnections.CollectionChanged -= XenConnection_CollectionChanged; - Properties.Settings.Default.SettingChanging -= new System.Configuration.SettingChangingEventHandler(Default_SettingChanging); - SearchPage.SearchChanged -= SearchPanel_SearchChanged; - - if (disposing && (components != null)) + if (disposing) { - components.Dispose(); + if (components != null) + components.Dispose(); - log.Debug("MainWindow disoposing license timer"); + pluginManager.Dispose(); + + log.Debug("MainWindow disposing of license timer"); if (licenseTimer != null) licenseTimer.Dispose(); } diff --git a/XenAdmin/MainWindow.cs b/XenAdmin/MainWindow.cs index dee67c227..452a04a34 100755 --- a/XenAdmin/MainWindow.cs +++ b/XenAdmin/MainWindow.cs @@ -213,7 +213,8 @@ namespace XenAdmin SRCollectionChangedWithInvoke = Program.ProgramInvokeHandler(CollectionChanged); FolderCollectionChangedWithInvoke = Program.ProgramInvokeHandler(CollectionChanged); TaskCollectionChangedWithInvoke = Program.ProgramInvokeHandler(MeddlingActionManager.TaskCollectionChanged); - ConnectionsManager.History.CollectionChanged += History_CollectionChanged; + + RegisterEvents(); CommandLineArgType = argType; CommandLineParam = args; @@ -224,16 +225,10 @@ namespace XenAdmin contextMenuBuilder = new ContextMenuBuilder(pluginManager, this); ((WinformsXenAdminConfigProvider) XenAdminConfigManager.Provider).PluginManager = pluginManager; - eventsPage.GoToXenObjectRequested += eventsPage_GoToXenObjectRequested; - SearchPage.SearchChanged += SearchPanel_SearchChanged; - Alert.RegisterAlertCollectionChanged(XenCenterAlerts_CollectionChanged); - Updates.RegisterCollectionChanged(Updates_CollectionChanged); - FormFontFixer.Fix(this); Folders.InitFolders(); DockerContainers.InitDockerContainers(); - OtherConfigAndTagsWatcher.InitEventHandlers(); // Fix colour of text on gradient panels TitleLabel.ForeColor = Program.TitleBarForeColor; @@ -243,7 +238,6 @@ namespace XenAdmin SelectionManager.BindTo(MainMenuBar.Items, this); SelectionManager.BindTo(ToolStrip.Items, this); - Properties.Settings.Default.SettingChanging += Default_SettingChanging; licenseTimer = new LicenseTimer(licenseManagerLauncher); GeneralPage.LicenseLauncher = licenseManagerLauncher; @@ -254,6 +248,32 @@ namespace XenAdmin statusLabelAlerts.Visible = statusLabelUpdates.Visible = statusLabelErrors.Visible = false; } + private void RegisterEvents() + { + //ClipboardViewer is registered in OnHandleCreated + OtherConfigAndTagsWatcher.RegisterEventHandlers(); + Alert.RegisterAlertCollectionChanged(XenCenterAlerts_CollectionChanged); + Updates.RegisterCollectionChanged(Updates_CollectionChanged); + ConnectionsManager.History.CollectionChanged += History_CollectionChanged; + //ConnectionsManager.XenConnections.CollectionChanged is registered in OnShown + Properties.Settings.Default.SettingChanging += Default_SettingChanging; + eventsPage.GoToXenObjectRequested += eventsPage_GoToXenObjectRequested; + SearchPage.SearchChanged += SearchPanel_SearchChanged; + } + + private void UnRegisterEvents() + { + Clip.UnregisterClipboardViewer(); + OtherConfigAndTagsWatcher.DeregisterEventHandlers(); + Alert.DeregisterAlertCollectionChanged(XenCenterAlerts_CollectionChanged); + Updates.DeregisterCollectionChanged(Updates_CollectionChanged); + ConnectionsManager.History.CollectionChanged -= History_CollectionChanged; + ConnectionsManager.XenConnections.CollectionChanged -= XenConnection_CollectionChanged; + Properties.Settings.Default.SettingChanging -= Default_SettingChanging; + eventsPage.GoToXenObjectRequested -= eventsPage_GoToXenObjectRequested; + SearchPage.SearchChanged -= SearchPanel_SearchChanged; + } + private void Default_SettingChanging(object sender, SettingChangingEventArgs e) { if (e == null) diff --git a/XenModel/OtherConfigWatcher.cs b/XenModel/OtherConfigWatcher.cs index d72c5fca2..d0af62b95 100644 --- a/XenModel/OtherConfigWatcher.cs +++ b/XenModel/OtherConfigWatcher.cs @@ -69,7 +69,7 @@ namespace XenAdmin } } - public static void InitEventHandlers() + public static void RegisterEventHandlers() { PoolCollectionChangedWithInvoke = InvokeHelper.InvokeHandler(CollectionChanged); VMCollectionChangedWithInvoke = InvokeHelper.InvokeHandler(CollectionChanged);