public bool AttachToProcess(Process process, EnvDTE.Process targetProcess, Guid[] engines = null) { // Retry the attach itself 3 times before displaying a Retry/Cancel // dialog to the user. var dte = GetDTE(); dte.SuppressUI = true; try { try { if (engines == null) { targetProcess.Attach(); } else { var process3 = targetProcess as EnvDTE90.Process3; if (process3 == null) { return(false); } process3.Attach2(engines.Select(engine => engine.ToString("B")).ToArray()); } return(true); } catch (COMException) { if (process.HasExited || process.WaitForExit(500)) { // Process exited while we were trying return(false); } } } finally { dte.SuppressUI = false; } // Another attempt, but display UI. var id = targetProcess.ProcessID; var t = targetProcess.Name; targetProcess.Attach(); return(true); }
public bool AttachToProcess(ProcessOutput processOutput, EnvDTE.Process process, Guid[] engines = null) { // Retry the attach itself 3 times before displaying a Retry/Cancel // dialog to the user. var dte = GetDTE(); dte.SuppressUI = true; try { try { if (engines == null) { process.Attach(); } else { var process3 = process as EnvDTE90.Process3; if (process3 == null) { return(false); } process3.Attach2(engines.Select(engine => engine.ToString("B")).ToArray()); } return(true); } catch (COMException) { if (processOutput.Wait(TimeSpan.FromMilliseconds(500))) { // Process exited while we were trying return(false); } } } finally { dte.SuppressUI = false; } // Another attempt, but display UI. process.Attach(); return(true); }