/// <summary> /// Attaches APE to the specified process so it can automate it /// </summary> /// <param name="process">The process to attach to</param> /// <param name="domain">The domain in the process to attach to</param> public static void AttachToProcess(Process process, string domain) { if (m_APE != null) { m_APE.RemoveFileMapping(); m_APE = null; } string processName = null; int processId = -1; try { processName = process.ProcessName; processId = process.Id; } catch { } if (process.HasExited) { if (string.IsNullOrEmpty(processName)) { throw GUI.ApeException("Process has exited"); } else { throw GUI.ApeException("Process " + processName + " has exited"); } } Stopwatch timer = Stopwatch.StartNew(); while (true) { // TODO maybe replace this with a visible top level non zero width / height window check instead? if (process.MainWindowHandle != IntPtr.Zero) { break; } if (timer.ElapsedMilliseconds > GetTimeOut()) { throw GUI.ApeException("Failed to locate process main window within " + GetTimeOut() + "ms timeout"); } Thread.Sleep(50); } m_APE = new APEIPC(process, domain); Log("Attached to process [" + m_APE.AUTProcessName + "] pid [" + m_APE.AUTProcessId + "]", LogItemType.Information); //Set the default timeout SetTimeOut(GetTimeOut()); }
private void BuildTree() { LocateButton.Enabled = false; //store a temp copy of m_Identity ControlIdentifier temp = m_Identity; WindowTree.Nodes.Clear(); PropertyListbox.Items.Clear(); m_CurrentAttached = (KeyValuePair <Process, string>)WinformsProcessesCombobox.SelectedItem; if (m_CurrentAttached.Key.HasExited) { WinformsProcessesCombobox.SelectedIndex = 0; Populate(); } else { if (m_CurrentAttached.Key.Id != Process.GetCurrentProcess().Id) { ListOfTopLevelWindows = new Dictionary <IntPtr, string>(); NM.EnumWindowsProc WindowsCallback = new NM.EnumWindowsProc(EnumProc); if (m_APE != null) { m_APE.RemoveFileMapping(); } if (AppDomainComboBox.Enabled) { string NewDomain = AppDomainComboBox.SelectedItem.ToString(); m_APE = new APEIPC(m_CurrentAttached.Key, NewDomain); } else { m_APE = new APEIPC(m_CurrentAttached.Key); } m_APE.TimeOut = 0; GC.Collect(); GC.WaitForPendingFinalizers(); NM.EnumWindows(WindowsCallback, new IntPtr(m_CurrentAttached.Key.Id)); } } //restore m_Identity m_Identity = temp; }
/// <summary> /// Attaches APE to the specified process so it can automate it /// </summary> /// <param name="process">The process to attach to</param> /// <param name="domain">The domain in the process to attach to</param> public static void AttachToProcess(Process process, string domain) { Log("Attached to process [" + process.ProcessName + "]", LogItemType.Information); Stopwatch timer = Stopwatch.StartNew(); while (true) { if (process.MainWindowHandle != IntPtr.Zero) { break; } if (timer.ElapsedMilliseconds > GetTimeOut()) { throw new Exception("Failed to locate process main window within " + GetTimeOut() + "ms timeout"); } Thread.Sleep(50); } process.WaitForInputIdle(); //Instead of GUI.m_APE.RemoveFileMapping we could do a //GUI.m_APE = null; //GC.Collect(); //GC.WaitForPendingFinalizers(); if (m_APE != null) { m_APE.RemoveFileMapping(); } m_APE = new APEIPC(process, domain); m_AttachedProcess = process; //Set the default timeout SetTimeOut(GetTimeOut()); }
public FormLeaks(APEIPC APE) { m_APE = APE; InitializeComponent(); }