CubaLibre CubaLibre - 8 months ago 46
C# Question

How to debug a C# .NET application in Visual Studio 2010 that is started from another process

I have a .NET GUI application written in C# and a PDF printer. The PDF printer has a field where you can set a command to start an external application.

In this case, I can print a document with this printer and the printer starts my EXE file with the filepath to the generated PDF file as argument. How can I debug my application when it is started from the printer?

In Visual Studio 2010, I can set debug information for command line arguments, and this works fine. But if the application is started from the printer the application doesn't work fine. Therefore I want to debug my application when it is started from printer. How can I do this? Is there a parameter to start an EXE file in debug mode or something like this?

Answer Source

You can attach to a process when it starts using a small registry tweak.

Go to

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options

Create a new key with the name of the executable as it will appear in Task Manager, for example, myapp.exe. Under this, create a new string value called debugger and set it to vsjitdebugger.exe.

Now, when the EXE file is triggered, a window will appear asking which debugger to attach to.