/// <summary> /// Keep HawkenExhaust alive if there's an update that requires UAC elevation /// </summary> private void HawkenReLauncher_OnLauncherClose(object sender) { Task waitUAC = Task.Factory.StartNew(() => GetWindowHandle("User Account Control")); waitUAC.Wait(); if (SimpleGameReLauncher.IsProcessRunning(this.launcherProcessName)) { this.LauncherQuitListener(this.launcherProcessName); return; } else { Environment.Exit(0); } }
/// <summary> /// This loop runs indefinetley looking for processName and then relaunching it. /// It runs on the main thread so as to keep the application alive. /// </summary> /// <param name="processName">name of the process to look for</param> /// <param name="processPath">path where process is located</param> protected void GameProcessListener(string processName, string processPath) { while (true) { Process process = null; while (process == null) { if (SimpleGameReLauncher.IsProcessRunning(processName)) { process = SimpleGameReLauncher.GetProcess(processName); process.Kill(); process.Dispose(); //Dispose the old process. break; } Thread.Sleep(500); } using (var gameProcess = Process.Start(Path.Combine(processPath, processName) + ".exe")) { gameProcess.WaitForExit(); } } }