I have a problem and I only came accross two or three posts around the web about it: When I’m using the clipboard in a C# application (Clipboard.SetText or Clipboard.Clear), Chrome is randomly already using it, so my clipboard request fails.
System.Runtime.InteropServices.ExternalException: Requested Clipboard operation did not succeed.
at System.Windows.Forms.Clipboard.ThrowIfFailed(Int32 hr)
at System.Windows.Forms.Clipboard.SetDataObject(Object data, Boolean copy, Int32 retryTimes, Int32 retryDelay)
at System.Windows.Forms.Clipboard.SetText(String text, TextDataFormat format)
at System.Windows.Forms.Clipboard.SetText(String text)
I close Chrome, it works, then reopen Chrome, and after some minutes, it still fails. I’m using the following code with a 1 second timer and GetOpenClipboardWindow(), another PInvoke :(, to confirm that this is really Chrome that is annoying me:
[DllImport("user32.dll")]
static extern IntPtr GetOpenClipboardWindow();
[DllImport("user32.dll", SetLastError = true)]
static extern int GetWindowThreadProcessId(IntPtr hWnd, out int
lpdwProcessId);
IntPtr hwnd = GetOpenClipboardWindow();
if (hwnd != IntPtr.Zero)
{
int processId;
GetWindowThreadProcessId(hwnd, out processId);
Process p = Process.GetProcessById(processId);
listBox1.Items.Add(p.Modules[0].FileName);
}
Does any of you already had this problem? Do you know why Chrome is stealing the clipboard?
[Edit]
At any of the Chrome team members: Dear developer, if you read this today, give me my Clipboard back as I have more rights than you on my Clipboard. I’ve been searching for two days because of you.
I’m afraid there is nothing left to do, If another process has the clipboard open, there is no way to free it until that process closes it.