I've been searching all over the net for answers to get a program to the foreground. I've been doing it the ghetto way by sending alt-tab keystrokes with SendKeys. I've tried this and it doesn't work,
private void execute()
{
setApp("League of Legends.exe");
Thread.Sleep(1500);
}
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
private static void setApp(String filename)
{
Process[] SameProcesses = Process.GetProcessesByName(filename);
Process SameProcess = SameProcesses[0];
if (SameProcess.Equals(null))
{
System.Windows.Forms.MessageBox.Show("No process");
}
else
{
SetForegroundWindow(SameProcess.MainWindowHandle);
}
}