internal void Close() { logger.ConditionalDebug("Close"); // since we handle the doc closing events, it is possible to close a window without having the // corresponding entry removed here (if the document is opened in multiple windows). In this case // I was once able to produce a situation where the corresponding configTaskPane was removed from // customTaskPanes in the background, and when we came here, it crashed. The pane was visible in the window that was closed // and was reused in a new window I created. So in order to avoid crashing in this strange // situation let's catch the exception. // The only way I can think of handlicng this cleanly would be with a window closing event, but I did not find out how to // get it (in word)... // I could also try to work on open events, but there is no window open event // Note that the Document.Close event does not fire at all in case of multiple windows on the same document // which is exactly the problem I am trying to address... try { configTaskPane.Visible = false; customTaskPanes.Remove(configTaskPane); configTaskPane.Dispose(); confContr.Dispose(); } catch // I do not know which kind of exception is raised in my strange case... We assume it means that everything // was already cleaned up. { logger.Error("Exception when closing a ConfigTaskPane"); } }
public static void RemoveTaskPane(CustomTaskPane taskPane, CustomTaskPaneCollection customTaskPanes) { //PLLog.Trace3("Enter", System.Data.Common.PROJECT_NAME); customTaskPanes.Remove(taskPane); //PLLog.Trace3("Exit", System.Data.Common.PROJECT_NAME); }
public void Remove(Guid id, bool savedToDrafts) { _customTaskPanes = Globals.ThisAddin.GetCustomTaskPaneCollection(); if (_alertTaskPanes.ContainsKey(id)) { _customTaskPanes.Remove(_alertTaskPanes[id]); CustomTaskPane ctp; _alertTaskPanes.TryRemove(id, out ctp); } RibbonButton button; if (_protectFilesButtons.TryRemove(id, out button)) { button.Click -= OnProtectFilesClick; } if (!savedToDrafts) RemoveSendLinkFolderIfTheMailWasNeverSent(id); RemoveTaskPane(id); }