Search code examples
c#wpfdebuggingattach-to-process

WPF Pass the debugger on to a newly spawned process


I have an application that spawns a new process. During development of the application, I would like to attach a debugger to the new process. Currently I can do that through Visual Studios Attach to Process functionality, but it's a pain to go back and attach it manually every single time when I need to test a minor change to the code.

Is it possible to spawn a new process using Process.Start and then attach any debuggers that are currently attached to the current process onto the new process?

I.E.:

Start Process1 with debugging enabled
Process1 starts Process2
Process1 attaches the debugger to Process2


Solution

  • Not a very clean solution, but you could do something like this:

    • In Process1, if you're running in Debug mode (Debugger.IsAttached), pass an argument to Process2 (e.g. process2.exe /debug)
    • In Process2, if the process is started with the /debug argument, attach the debugger from code (Debugger.Launch())