From 7d713682ba0c4c0dd8699b5727bf3b281fda2c04 Mon Sep 17 00:00:00 2001 From: Paddy Xu Date: Sat, 27 May 2017 00:41:10 +0300 Subject: [PATCH] the plug-in might be disposed before COM finishes when pressing SPACE key tooooo fast --- .../PreviewHandlerHost.cs | 3 +++ .../QuickLook.Plugin.IPreviewHandlers/PreviewPanel.xaml.cs | 7 +++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/PreviewHandlerHost.cs b/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/PreviewHandlerHost.cs index e77a770..09d9f4c 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/PreviewHandlerHost.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/PreviewHandlerHost.cs @@ -127,6 +127,9 @@ namespace QuickLook.Plugin.IPreviewHandlers if (_mCurrentPreviewHandler == null) return false; + if (IsDisposed) + return false; + // bind the preview handler to the control's bounds and preview the content var r = ClientRectangle; _mCurrentPreviewHandler.SetWindow(Handle, ref r); diff --git a/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/PreviewPanel.xaml.cs b/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/PreviewPanel.xaml.cs index 48fbdc2..640d101 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/PreviewPanel.xaml.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/PreviewPanel.xaml.cs @@ -1,7 +1,6 @@ using System; using System.Runtime.InteropServices; using System.Windows.Controls; -using System.Windows.Interop; using System.Windows.Threading; namespace QuickLook.Plugin.IPreviewHandlers @@ -37,10 +36,10 @@ namespace QuickLook.Plugin.IPreviewHandlers _control = new PreviewHandlerHost(); presenter.Child = _control; _control.Open(file); - }), DispatcherPriority.Render); + }), DispatcherPriority.Loaded); - SetForegroundWindow(new WindowInteropHelper(context.ViewerWindow).Handle); - SetActiveWindow(presenter.Handle); + //SetForegroundWindow(new WindowInteropHelper(context.ViewerWindow).Handle); + //SetActiveWindow(presenter.Handle); } [DllImport("user32.dll")]