From 2df23b5ee46ff2ebd9f6413a4ea1aed13ec8fc34 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Wed, 28 Apr 2010 15:06:18 +0000 Subject: [PATCH] Fix SD2-1638: Unable to re-open SharpDevelop's window under Vista after minimizing git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@5731 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Src/TextEditor/ClipboardHandling.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Main/Base/Project/Src/TextEditor/ClipboardHandling.cs b/src/Main/Base/Project/Src/TextEditor/ClipboardHandling.cs index 83575e204c..75e17a445a 100644 --- a/src/Main/Base/Project/Src/TextEditor/ClipboardHandling.cs +++ b/src/Main/Base/Project/Src/TextEditor/ClipboardHandling.cs @@ -5,11 +5,14 @@ // $Revision$ // -using ICSharpCode.SharpDevelop.Util; using System; +using System.Runtime.InteropServices; using System.Threading; + using ICSharpCode.Core.WinForms; using ICSharpCode.SharpDevelop.Gui; +using ICSharpCode.SharpDevelop.Util; +using Microsoft.Win32.SafeHandles; namespace ICSharpCode.SharpDevelop.DefaultEditor { @@ -65,9 +68,16 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor } currentWorker = workerThread.Enqueue(DoUpdate); // wait a few ms in case the clipboard can be accessed without problems - currentWorker.AsyncWaitHandle.WaitOne(50); + WaitForSingleObject(currentWorker.AsyncWaitHandle.SafeWaitHandle, 50); + // Using WaitHandle.WaitOne() pumps some Win32 messages. + // To avoid unintended reentrancy, we need to avoid pumping messages, + // so we directly call the Win32 WaitForSingleObject function. + // See SD2-1638 for details. } + [DllImport("kernel32", SetLastError=true, ExactSpelling=true)] + static extern Int32 WaitForSingleObject(SafeWaitHandle handle, Int32 milliseconds); + static void DoUpdate() { clipboardContainsText = ClipboardWrapper.ContainsText;