Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio: auto attach to a process when the process is spawned

I want to attach to a process(a.exe) as soon as it is spawned, is it doable with VS? I only know the name of the process. Actually what I want to accomplish is set a breakpoint in c# code, but the code is belonging to another executable which will be launched by current running application(c.exe). The code is inside the initialize period so it is impossible for me to do the attach manually.

like image 916
Bin Chen Avatar asked Dec 23 '09 07:12

Bin Chen


People also ask

How do I attach Visual Studio to a process that is not started yet?

Add the free Reattach Extension for Visual Studio. Ask it to reattach to the process name before it is launched. It will pop a modal dialog saying it is waiting for the process name to launch. Now launch the process and the Visual Studio debugger will attach immediately, catching exceptions and hitting breakpoints.

How do you Debug using attach to process?

In Visual Studio 2015, click 'Debug > Attach to process' in the menu. Alternatively, there is a shortcut key Ctrl+Alt+P. Show activity on this post. You can do this in your code.

How do I add multiple processes in Visual Studio?

With the app running, select Debug > Attach to Process. In the Attach to Process dialog box, select the process from the Available Processes list, and then select Attach.


1 Answers

When I've faced this situation before (and I controlled both processes), I found a decent workaround is to put a call to Debugger.Launch() in the spawning process' entry point. VS will then pop up a dialog box and let you attach to the process.

like image 119
Mark Simpson Avatar answered Dec 04 '22 01:12

Mark Simpson