Clipboard copy operation hangs on WPF form in WinForm application

-1

I'm working on a WinForm application that includes a WPF form. I call ElementHost.EnableModelessKeyboardInterop(this) in the constructor of the WPF form. Everything seems to be working fine, except for clipboard copying.

When I select text from any control on the WPF form (a TextBox, for example) and copy, the application hangs for about 2 seconds and then everything continues as normal. Turns out an exception is being thrown and seems to be handled somewhere along the call stack; the copy operation ends up working, but not before the UI thread hangs for a bit.

The Exception is a COMException raised in System.Windows.Clipboard.Flush with message "OpenClipboard Failed (Exception from HRESULT: 0x800401D0 (CLIPBRD_E_CANT_OPEN))".

From another question asked on here (How do I copy the contents of a String to the clipboard in C#?), my understanding is that that Clipboard class is the one used by WPF. I'm thinking the failure probably comes from the fact that the WPF Clipbard class is being used in a WinForm application... it clearly handles the exception somewhere since the copy still works... Just not sure why it hangs or if there's something I need to do to avoid that problem when using a WPF form in a WinForm application?

wpf
wpf-interop
asked on Stack Overflow Nov 28, 2018 by Ben Martin

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0