@@ -37,6 +37,7 @@ public void Open()
37
37
if ( -- i == 0 ) ThrowOpenFailed ( ) ;
38
38
Thread . Sleep ( RETRY_DELAY ) ;
39
39
}
40
+
40
41
_isOpen = true ;
41
42
}
42
43
@@ -53,6 +54,7 @@ public async Task OpenAsync()
53
54
if ( -- i == 0 ) ThrowOpenFailed ( ) ;
54
55
await Task . Delay ( RETRY_DELAY ) . ConfigureAwait ( false ) ;
55
56
}
57
+
56
58
_isOpen = true ;
57
59
}
58
60
@@ -393,30 +395,27 @@ protected void ThrowOpenFailed()
393
395
var hr = Marshal . GetLastWin32Error ( ) ;
394
396
var mex = Marshal . GetExceptionForHR ( hr ) ;
395
397
396
- if ( hr == 5 ) // ACCESS DENIED
398
+ try
397
399
{
398
- IntPtr hwnd = NativeMethods . GetOpenClipboardWindow ( ) ;
399
- if ( hwnd != IntPtr . Zero )
400
+ if ( hr == 5 ) // ACCESS DENIED
400
401
{
401
- uint threadId = NativeMethods . GetWindowThreadProcessId ( hwnd , out var processId ) ;
402
- string processName = "Unknown" ;
403
- try
402
+ IntPtr hwnd = NativeMethods . GetOpenClipboardWindow ( ) ;
403
+ if ( hwnd != IntPtr . Zero )
404
404
{
405
+ uint threadId = NativeMethods . GetWindowThreadProcessId ( hwnd , out var processId ) ;
406
+ string processName = "Unknown" ;
405
407
var p = Process . GetProcessById ( ( int ) processId ) ;
406
408
processName = p . ProcessName ;
409
+ throw new ClipboardBusyException ( ( int ) processId , processName , mex ) ;
407
410
}
408
- catch { }
409
-
410
- throw new ClipboardBusyException ( ( int ) processId , processName , mex ) ;
411
-
412
- }
413
- else
414
- {
415
- throw new ClipboardBusyException ( mex ) ;
416
411
}
417
412
}
413
+ catch
414
+ {
415
+ // if we can't get the process name locking clipboard, just throw the original exception
416
+ }
418
417
419
- throw mex ;
418
+ throw new ClipboardBusyException ( mex ) ;
420
419
}
421
420
}
422
- }
421
+ }
0 commit comments