#85 Proper fix for KeePass freezing the window manager under Mono

Will R

My last patch on this issue turned out not to solve the underlying problem, however since discovering it is fully reproducible I have been able to implement a complete fix building off the previous patches AppRunFlags support.

To replicate the issue under Mono, the following steps are needed:

  1. Open a KeePass database.
  2. Open an entry for editing.
  3. Select any text box, press Ctrl+C.
  4. Close the entry for editing.
  5. Double-click a password field to copy it to the clipboard.

Under the best case, KeePass will freeze, under Cinnamon, the entire desktop will freeze accepting input (but the mouse will keep moving).

This problem is due to the fact that the X clipboard isn't a separate memory space, and so Mono simply passes a pointer to the clipboard's memory location. However, since this is in the main UI thread (which is blocked waiting for xsel), xsel blocks waiting for the clipboard's ownership to be released, the UI thread blocks waiting for xsel, and the window manager blocks waiting for UI thread.

This problem is entirely resolved in this patch by modifying NativeLib.RunConsoleApp() to asynchronously execute and wait for the xsel process in a separate thread, and then calling DoEvents() while waiting, which allows the UI thread to handle events such as requests for the clipboard. To prevent problems with re-entrant functions, all forms are disabled during this time, and re-enabled afterwards.

This implementation perfectly preserves the synchronous nature of the RunConsoleApp() call otherwise, and absent the RunAppFlags.DoEventsWorkAround flag, executes the call synchronously.

1 Attachments


  • Will R

    Will R - 2013-10-26

    This ticket is for KeePass 2.x (it was accidentally tagged for 1.x, but I don't seem to have permission to edit it).

  • Dominik Reichl

    Dominik Reichl - 2013-10-26
    • status: open --> closed
    • Group: KeePass_1.x --> KeePass_2.x
  • Dominik Reichl

    Dominik Reichl - 2013-10-26

    Thanks. I've included your patch and applied a few modifications (made form disabling optional, forms are re-enabled in reverse order, increased sleep to 4 ms, ...).

    The latest development snapshot (including the 3 modified source code files) is here:

    Best regards,

  • Dominik Reichl

    Dominik Reichl - 2013-10-26

    I've set the Thread.Sleep to 2 ms now.

    Best regards,


Log in to post a comment.