Harden clipboard writes against "clipboard in use" failures#649
Merged
Conversation
Windows clipboard access throws ExternalException when another application (clipboard manager, RDP, Office, ...) holds the clipboard open - even after the WinForms-internal retries. Copying in edit mode, copying marked lines, copying the tab path, and the copy buttons in ExceptionWindow/PluginHashDialog all crashed into the exception dialog (previously reported in #195). All clipboard writes now go through ClipboardHelper.TrySetText / TrySetDataObject, which report failure instead of throwing. LogWindow shows the failure in the status line, LogTabWindow/PluginHashDialog show a message box, and ExceptionWindow fails silently so the error dialog can never cascade. Also fixes the literal \n\n (verbatim string) in ExceptionWindow and uses copy: true for SetDataObject so copied lines survive app exit, matching SetText.
Use the Vanara.PInvoke.User32 package instead of manual DllImports in the clipboard lock test fixture, drop the redundant error logging in ClipboardHelper (every call site already surfaces the failure), and simplify the PluginHashDialog copy handler to a ternary.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Windows clipboard access throws
ExternalException("Requested Clipboard operation did not succeed") when another application holds the clipboard open — clipboard managers, RDP, Office, launcher tools — even after the WinForms-internal retries (10 × 100 ms). Every clipboard write in LogExpert was unguarded, so a busy clipboard crashed straight into the exception dialog. Previously reported in #195, where the reporter traced it to a clipboard-monitoring launcher app; the code was never hardened.Changes
ClipboardHelper(LogExpert.UI.Extensions) withTrySetText/TrySetDataObject— catchesExternalExceptionand reports failure via return value instead of crashing.TrySetDataObjectusescopy: trueso copied data survives app exit (previously inconsistent withSetText).LogWindowedit-mode copy + bothCopyMarkedLinesToClipboardpaths → status-line errorLogTabWindowcopy-path-to-clipboard → warning message boxPluginHashDialog→ keeps its success/error message boxes, drops its local try/catchExceptionWindow→ fails silently so the error dialog can never cascade into another error@"\n\n"literal inExceptionWindow— error reports showed a literal\n\ninstead of blank lines, both in the dialog and in copied text.LogExpert_Common_UI_Message_ClipboardInUse(en/de/zh-CN).Tests
Four new tests (TDD, red→green) exercise the helper against the real clipboard:
success paths verify the text lands on the clipboard; failure paths hold the Win32 clipboard open from a background thread via
Vanara.PInvoke.User32.OpenClipboard— reproducing exactly what an external clipboard tool causes — and assert the helperreturns
falseinstead of throwing. Full suite: 848 passed, 0 failed.