private static void exitProcess(object sender, EventArgs e) { // Prevent from recursion if (ProcessStatus == ProcessStatuses.WOW_CLOSED) { return; } // Do it first ProcessStatus = ProcessStatuses.WOW_CLOSED; GameStatus = GameStatuses.NOT_STARTED; // Blah blah blah after Log("char", "WoW termination detected"); Debug("char", "Executing After WoW termination ..."); // Cleaning WowHWND = 0; Injector.IsLuaRegistered = false; Injector.ClearLuaInjection(); wowProcess.CloseProcess(); // TODO Check for crush if (WoWProcessEnded != null) { WoWProcessEnded(((Process)sender).Id); } Debug("char", "WoW termination completed"); // Check for crush uint err_pid = AppHelper.FindPidWindowByTitle(AppHelper.WOWERROR_APP_NAME); if (err_pid != 0 && config.Account.ReStart) { Log("char", "Crush detected. Clearing task list ... "); Process err_proc = null; try { err_proc = System. Diagnostics.Process.GetProcessById((int)err_pid); } catch { // Nothing wrong. Might be closed already by user. } do { try { if (process != null) { process.Kill(); } } catch { // Already killed process = null; } try { if (err_proc != null) { err_proc.Kill(); err_proc = System.Diagnostics.Process.GetProcessById((int)err_pid); } } catch { // Already killed or doesn't exists on the list err_proc = null; } Thread.Sleep(1000); } while (process != null || err_proc != null); Log("char", "Cleaing completed. Restarting bot ... "); StartBot(); } else { ProcessStatus = ProcessStatuses.IDLE; } }