Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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");

I want it to be something like this:

if (Debugger.IsAttached)
    // start "sample.exe" in the same debugging session
else
    Process.Start("sample.exe");

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.

like image 310
Rohit Avatar asked Jan 27 '11 08:01

Rohit


2 Answers

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");
like image 83
Sergey Berezovskiy Avatar answered Sep 23 '22 12:09

Sergey Berezovskiy


you can change the properties of your solution to start multiple apps.

an explanation is here Run Multiple projects

The MSDN article is here MSDN Article on running multiple projects

like image 25
Kev Hunter Avatar answered Sep 23 '22 12:09

Kev Hunter