internal void UnloadPlugin() { // the focused element will not processed by GC: https://stackoverflow.com/questions/30848939/memory-leak-due-to-window-efectivevalues-retention FocusManager.SetFocusedElement(this, null); Keyboard.DefaultRestoreFocusMode = RestoreFocusMode.None; // WPF will put the focused item into a "_restoreFocus" list ... omg Keyboard.ClearFocus(); _canOldPluginResize = ContextObject.CanResize; ContextObject.Reset(); try { Plugin?.Cleanup(); } catch (Exception e) { Debug.WriteLine(e); } Plugin = null; _path = string.Empty; }
internal void BeginShow(IViewer matchedPlugin, string path, Action <string, ExceptionDispatchInfo> exceptionHandler) { _path = path; Plugin = matchedPlugin; ContextObject.Reset(); // assign monitor color profile ContextObject.ColorProfileName = DisplayDeviceHelper.GetMonitorColorProfileFromWindow(this); // get window size before showing it try { Plugin.Prepare(path, ContextObject); } catch (Exception e) { exceptionHandler(path, ExceptionDispatchInfo.Capture(e)); return; } SetOpenWithButtonAndPath(); // revert UI changes ContextObject.IsBusy = true; var newHeight = ContextObject.PreferredSize.Height + BorderThickness.Top + BorderThickness.Bottom + (ContextObject.TitlebarOverlap ? 0 : windowCaptionContainer.Height); var newWidth = ContextObject.PreferredSize.Width + BorderThickness.Left + BorderThickness.Right; var newSize = new Size(newWidth, newHeight); // if use has adjusted the window size, keep it if (_customWindowSize != Size.Empty) { newSize = _customWindowSize; } else { _ignoreNextWindowSizeChange = true; } PositionWindow(newSize); if (Visibility != Visibility.Visible) { Dispatcher.BeginInvoke(new Action(() => this.BringToFront(Topmost)), DispatcherPriority.Render); Show(); } //ShowWindowCaptionContainer(null, null); //WindowHelper.SetActivate(new WindowInteropHelper(this), ContextObject.CanFocus); // load plugin, do not block UI Dispatcher.BeginInvoke(new Action(() => { try { Plugin.View(path, ContextObject); } catch (Exception e) { exceptionHandler(path, ExceptionDispatchInfo.Capture(e)); } }), DispatcherPriority.Input); }