public static void SetForegroundWindow(IntPtr windowHandle)
{
// Check if the handle is valid
HandleManipulator.ValidateAsArgument(windowHandle, "windowHandle");
// If the window is already activated, do nothing
if (GetForegroundWindow() == windowHandle)
return;
// Restore the window if minimized
ShowWindow(windowHandle, WindowStates.Restore);
// Activate the window
if(!NativeMethods.SetForegroundWindow(windowHandle))
throw new ApplicationException("Couldn't set the window to foreground.");
}