From 6a84cddd57ee4e75735825afa53c9aeb73bcd344 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Wed, 24 Aug 2005 13:20:23 +0000 Subject: [PATCH] Add a "DoEvents" call to the workaround for SD2-426. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@430 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Src/Gui/TextAreaClipboardHandler.cs | 23 ++++++++++++++++--- .../Core/Project/Src/Util/ClipboardWrapper.cs | 15 +++++++++++- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaClipboardHandler.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaClipboardHandler.cs index e945e04796..ea7b82bdc4 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaClipboardHandler.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaClipboardHandler.cs @@ -87,10 +87,27 @@ namespace ICSharpCode.TextEditor dataObject.SetData(DataFormats.Rtf, RtfWriter.GenerateRtf(textArea)); } OnCopyText(new CopyTextEventArgs(str)); - Clipboard.SetDataObject(dataObject, true, 50, 50); - return true; + + // Work around ExternalException bug. (SD2-426) + // Best reproducable inside Virtual PC. + // SetDataObject has "retry" parameters, but apparently a call to "DoEvents" + // is necessary for the workaround to work. + int i = 0; + while (true) { + try { + Clipboard.SetDataObject(dataObject, true, 5, 50); + return true; + } catch (ExternalException) { + if (i++ > 5) + throw; + } + System.Threading.Thread.Sleep(50); + Application.DoEvents(); + System.Threading.Thread.Sleep(50); + } + } else { + return false; } - return false; } public void Cut(object sender, EventArgs e) diff --git a/src/Main/Core/Project/Src/Util/ClipboardWrapper.cs b/src/Main/Core/Project/Src/Util/ClipboardWrapper.cs index 8f49232277..4c06870d22 100644 --- a/src/Main/Core/Project/Src/Util/ClipboardWrapper.cs +++ b/src/Main/Core/Project/Src/Util/ClipboardWrapper.cs @@ -19,6 +19,7 @@ namespace ICSharpCode.Core public static bool ContainsText { get { try { + LoggingService.Debug("ContainsText called"); return Clipboard.ContainsText(); } catch (ExternalException) { return false; @@ -55,7 +56,19 @@ namespace ICSharpCode.Core public static void SetDataObject(object data) { - Clipboard.SetDataObject(data, true, 50, 50); + int i = 0; + while (true) { + try { + Clipboard.SetDataObject(data, true, 5, 50); + return; + } catch (ExternalException) { + if (i++ > 5) + throw; + } + System.Threading.Thread.Sleep(50); + Application.DoEvents(); + System.Threading.Thread.Sleep(50); + } } } }