I have a peculiar error where some process occasionally appears to be using the clipboard when my application goes to handle copy & paste operations. There are some retry work arounds, and I have an acceptable solution in place, but I would like to locate which process it is if the error occurs again.
I've wrapped my solution into an easy-to-use method (and some declarations):
[DllImport("user32.dll", SetLastError = true)] static extern IntPtr GetOpenClipboardWindow(); [DllImport("user32.dll", SetLastError = true)] static extern int GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId); private static Process GetProcessLockingClipboard() { int processId; GetWindowThreadProcessId(GetOpenClipboardWindow(), out processId); return Process.GetProcessById(processId); }
Enjoy!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With