private void HandleLeagueProcessLaunched(LeagueProcessDetectedArgs e) { lock (synchronization) { var processId = e.ProcessDescriptor.ProcessId; var process = processProxy.GetProcessOrNull(processId); if (process == null) { logger.Error("League process " + processId + " of type " + e.ProcessType + " quit too quickly!"); return; } logger.Info("Handling process " + processId + " launch"); if (e.ProcessType == LeagueProcessType.RadsUserKernel && sessionsByProcessId.Any()) { var sessions = sessionsByProcessId.Values.Distinct(); var session = sessions.First(); IProcess foregroundProcess; if (session.TryGetProcess(LeagueProcessType.GameClient, out foregroundProcess) || session.TryGetProcess(LeagueProcessType.PvpNetClient, out foregroundProcess) || session.TryGetProcess(LeagueProcessType.Launcher, out foregroundProcess)) { var foregroundProcessDerp = Process.GetProcessById(foregroundProcess.Id); List <IntPtr> processWindowHandles = new List <IntPtr>(); foreach (ProcessThread thread in foregroundProcessDerp.Threads) { WinAPI.EnumThreadWindows(thread.Id, (hWnd, lparam) => { processWindowHandles.Add(hWnd); return(true); }, IntPtr.Zero); } foreach (var processWindowHandle in processWindowHandles) { if (WinAPI.IsWindowVisible(processWindowHandle)) { WinAPI.SetForegroundWindow(processWindowHandle); WinAPI.ShowWindow(processWindowHandle, WinAPI.WindowShowStyle.Minimize); WinAPI.ShowWindow(processWindowHandle, WinAPI.WindowShowStyle.Restore); } } Process.GetProcessById(process.Id).Kill(); return; } } process.EnableRaisingEvents = true; process.Exited += (a, b) => HandleLeagueProcessQuit(process, e.ProcessType); if (process.HasExited) { logger.Info("Process " + process.Id + " exited too quickly!"); } bool processKilled = false; // todo: event for process detected allowing for duplicate RUK kill if (!processKilled) { LeagueSession session; var parentProcessId = e.ProcessDescriptor.ParentProcessId; if (!sessionsByProcessId.TryGetValue(parentProcessId, out session)) { logger.Info("Creating new session for " + processId + " as parent process not found " + parentProcessId); session = new LeagueSession(); OnSessionCreated(new LeagueSessionCreatedArgs(session)); } logger.Info("Adding process " + processId + " to session " + session); logger.Info("!"); session.HandleProcessLaunched(process, e.ProcessType); sessionsByProcessId.Add(processId, session); logger.Info("==> " + sessionsByProcessId.Count); } } }