How to start a child process in the same Visual Studio debugging session as the parent, programmatically?

后端 未结 4 1834
攒了一身酷
攒了一身酷 2020-12-15 05:28

When running a process under the debugger, I would like to start a child process in the same debugger.

Currently, I use

Process.Start(\"sample.exe\")         


        
4条回答
  •  情话喂你
    2020-12-15 06:02

    You should attach debugger to process you are starting. This could be done:

    1. Manually from Visual Studio after starting "sample.exe" select it menu Debug > Attach to process..
    2. Programmatically attach debugger inside "sample.exe"
    3. Attaching to a Process using VS.NET Automation Model
    4. 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)
    5. Some external tool maybe

    Here is code for "sample.exe" to attach debugger:

    if (!Debugger.IsAttached)
         Debugger.Launch();
    Debugger.Break();
    

    You should pass some parameter to "sample.exe" to verify if you need to attach debugger.

    Process.Start("sample.exe", "Debug=true");
    

提交回复
热议问题