I have two C# WinForm projects in the same solution lets call them A and B. Project A starts Process B via a call like below
ProcessStartInfo psi = new Proce
Try getting the process ID from Program B, something like:
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = Task.EXEFilename;
psi.WorkingDirectory = Path.GetDirectoryName(Data.EXEFilename);
var proc = Process.Start(psi);
Debug.WriteLine(proc.Id);
Then load your project up in another instance of Visual Studio and use Debug > Attach to process to attach to Program B.
In the 2nd project have it check its command line arguments, if it sees something like --debug
was passed in as the first argument the 2nd program launches the debugger itself
private static void Main(string[] args)
{
//If no debugger is attached and the argument --debug was passed launch the debugger
if (args.Length == 1 && args[0] == "--debug" && Debugger.IsAttached == false)
Debugger.Launch();
//(snip) the rest of your program
}
When you do this you will get a dialog window that will allow you to choose to open a new copy of Visual Studio or just use your already open copy.
You can also put the child process in the Image File Execution Options registry key.
It sounds like you want Visual Studio to automatically attach to any child processes that are created during debugging. Other debuggers like windbg have this behavior but unfortunately Visual Studio does not. There is a user voice item which is tracking this request though
Short term though the best option is to do simply break at the point the child process is spawned and manually attach the debugger.
var proc = Process.Start(psi);
Debugger.Break();
Here is a solution I was shown...
Add a message box to the project you want to debug, Project B.
MessageBox.Show("pause");
Add a breakpoint some point after the message box code above, in Project B.
Run the code until the message box appears. message box image
Select Debug > Attach to Process
In the window that appears, select the name of the project you are executing and wish to step through, Project B. Click OK.
Click OK on the message box which was created by the message box code. message box image
You should now be at the breakpoint you placed sometime after the message box code in Project B!
You can also try not launching process B directly. Right-click on the solution, select Properties | Common Properties | Startup. Set both Process A and Process B to Start. This simulates Process B being launched by process A (comment out the launching of process B by process A in the source code of A). You can now test your interprocess communications between A and B as if B had been launched by A.