Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine which process is locking the clipboard

Tags:

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.

like image 861
Richard Pianka Avatar asked Jul 05 '11 13:07

Richard Pianka


Video Answer


1 Answers

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!

like image 146
Richard Pianka Avatar answered Sep 30 '22 08:09

Richard Pianka