public static void SetForegroundWindow(WindowHandle hWnd) { if (hWnd == null) throw new ArgumentNullException(paramName: nameof(hWnd)); var isSet = TrySetForegroundWindow(hWnd); if (!isSet) throw new InvalidOperationException( String.Format( "Failed to set foreground window {0}", hWnd.DangerousGetHandle()); }