Hi
I have implemented the XamGrid copy to clipboard operation using the XamGrid.CopyToClipboard method. The method works fine if I do not have notepad++ open. If its open and if I try a copy using Ctrl+C then it fails with the following error.
OpenClipboard Failed (Exception from HRESULT: 0x800401D0 (CLIPBRD_E_CANT_OPEN)) ErrorCode:-2147221040
Kindly let me know what can be done. Also, please note that I cannot add any App.xaml code handlers because I cannot change that file.
Thanks
Chev
Did you tried surrounding the call to CopyToClipboard in try catch block and if an COMException is thrown retry one more time after a while? If you provide the version of notepad++ and what if you have any plugins installed?
Regards,
Sorry I did not get the time to test it again. The issue still persists. Currently it is not of high priority
Hi Chev,
I am just checking if you got this worked out or you still require any assistance or clarification on the matter.
I've tested similar scenario and was not able to reproduce this issue. Could you please provide a sample project where it is easily reproducible?
Are you reproducing this consistently(for every invoke of XamGrid.CopyToClipboard() when the notepad++ is running)? Such an exception usually occurs during concurrent access to the clipboard. Is it happening when you try to copy text from a TextBox for example? Do you have any notepad++ plugins that are doing something with the clipboard ?
As a workaround you could wrap the XamGrid.CopyToClipboard() method in try catch and look for COMException - if such an exception is thrown the best solution is to add a short wait(I suppose few milliseconds would be enough) and try again(and probably make few more trials) - if it is still failing most probably some other application has opened the clipboard and kept it open for quite some time.