如何在同一的Visual Studio调试会话作为父启动子进程,以编程? [英] How to start a child process in the same Visual Studio debugging session as the parent, programmatically?
问题描述
在调试器下运行的过程中,我想开始在同一个调试子进程。
When running a process under the debugger, I would like to start a child process in the same debugger.
目前,我用
Process.Start("sample.exe");
我希望它是这样的:
I want it to be something like this:
if (Debugger.IsAttached)
// start "sample.exe" in the same debugging session
else
Process.Start("sample.exe");
我能通过一个标志,指示它来调用子进程调试.Launch()
,但不会赶上启动的错误,并导致调试会话,其中有些功能没有启用(如编辑并继续等)。这是最好有调试器直接启动的过程。
I could pass a flag to the child process that instructs it to call Debugger.Launch()
, but that won't catch start up errors, and it results in a debugging session where some features are not enabled (such as edit and continue, etc). It's preferable to have the debugger launch the process directly.
推荐答案
您要重视调试器来处理你开始。可以这样做:
You should attach debugger to process you are starting. This could be done:
- 手动从Visual Studio开始SAMPLE.EXE中选择菜单调试>附加处理后..
- 编程重视内部SAMPLE.EXE
- 的使用VS.NET自动化模型
- 更新::您可以设置windows环境下附调试器每次SAMPLE.EXE开头:启动调试器自动一>(您需要无论如何调用Debugger.Break)
- 某些外部工具也许
调试
附加到进程的
- Manually from Visual Studio after starting "sample.exe" select it menu Debug > Attach to process..
- Programmatically attach debugger inside "sample.exe"
- Attaching to a Process using VS.NET Automation Model
- UPDATE: You can setup windows environment to attach debugger every time "sample.exe" starts: Launch the Debugger Automatically (you will need to call Debugger.Break anyway)
- Some external tool maybe
这里是代码SAMPLE.EXE附加调试器:(!Debugger.IsAttached)
Here is code for "sample.exe" to attach debugger:
if (!Debugger.IsAttached)
Debugger.Launch();
Debugger.Break();
您应该通过一些参数设置为SAMPLE.EXE,以验证是否需要附加调试器。
You should pass some parameter to "sample.exe" to verify if you need to attach debugger.
Process.Start("sample.exe", "Debug=true");
这篇关于如何在同一的Visual Studio调试会话作为父启动子进程,以编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!