public static void BringWindowToFront(int processid)
{
//get the process
System.Diagnostics.Process bProcess = System.Diagnostics.Process.GetProcessById(processid);// FirstOrDefault<System.Diagnostics.Process>;
//check if the process is nothing or not.
if (bProcess != null)
{
//get the (int) hWnd of the process
IntPtr hwnd = bProcess.MainWindowHandle;
//check if its nothing
if (hwnd != IntPtr.Zero)
{
//if the handle is other than 0, then set the active window
bProcess.WaitForInputIdle();
SetForegroundWindow(hwnd);
}
else
{
//we can assume that it is fully hidden or minimized, so lets show it!
bProcess.WaitForInputIdle();
ShowWindow(hwnd, ShowWindowEnum.Restore);
SetForegroundWindow(hwnd);
}
}
else
{
//tthe process is nothing, so start it
//System.Diagnostics.Process.Start(@"C:\Program Files\B\B.exe");
}
}