Menu

#18 Clipboard is locked

1.0.7
Fixed
nobody
None
Medium
Defect
2013-12-10
2013-12-10
Anonymous
No

Originally created by: mik...@rogers.com
Originally owned by: tortoisesvn

It seems that when I use copy/paste in Bowpad and keep Bowpad open, the clipboard gets locked I cannot use the clipboard in my own app.

Here is the stacktrace (truncated for privacy) I get when trying to copy/paste in my app when Bowpad is open after performing copy/paste in Bowpad:

OpenClipboard Failed (Exception from HRESULT: 0x800401D0 (CLIPBRD_E_CANT_OPEN))
System.Runtime.InteropServices.COMException (0x800401D0): OpenClipboard Failed (Exception from HRESULT: 0x800401D0 (CLIPBRD_E_CANT_OPEN))
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at System.Windows.Clipboard.Flush()

What version of the product are you using? On what operating system?
1.0.6 build 476 x64 on Windows 7

Discussion

  • Anonymous

    Anonymous - 2013-12-10

    Originally posted by: tortoisesvn

    I've double and tripple checked the code, and the clipboard is closed properly every time it's opened.
    But I think what you're experiencing here is a well known race condition which you simply forgot to handle properly. See here for an example:
    http://blogs.msdn.com/b/rds/archive/2006/11/20/why-does-my-shared-clipboard-not-work-part-2.aspx

    Basically here's what's happening:
    BowPad monitors the clipboard for changes. Every time the contents of the clipboard change, it gets a notification from the OS.
    When such a notification is sent, BowPad opens the clipboard and reads out the text (if there is text) and stores that text. That way it can keep a history of texts on the clipboard (to see this in action, copy several texts to the clipboard, then hit Ctrl+Shift+V in BowPad).

    My guess is that your app opens the clipboard, changes the content of the clipboard, closes the clipboard and then shortly thereafter opens the clipboard again to do some more work. But the second time opening the clipboard fails, because BowPad has the clipboard opened because of the notification it gets from the first clipboard change.

    To work around this race condition, you have to retry opening the clipboard a few times (BowPad and other apps with clipboard-history features only open the clipboard for a very, very short time so you don't have to retry often or long). But you have to implement a retry or deal with the fact that some other app has the clipboard open.

    See the link I mentioned above - it explains everything very well.

    I can only try to reduce both the time BowPad has the clipboard open and reduce the times it opens the clipboard, but I can not get rid of that race condition - that's simply not possible. The clipboard is a shared resource and your app has to deal properly with that fact.

    Labels: Milestone-1.0.7
    Owner: tortoisesvn
    Status: Started

     
  • Anonymous

    Anonymous - 2013-12-10

    Originally posted by: tortoisesvn

    This issue was closed by revision [r493].

    Status: Fixed

     
MongoDB Logo MongoDB