views:

83

answers:

4

Hi. I am new to programming. I know only Start debug before. Maybe start debug suit for some small application develop better.

I found Visual studio IDE provide another method of attach to process for using. When & Why must I use the attach debugging?

Such as multi-threading application debugging. Client/Service application debugging. etc. Thank you.

+2  A: 

Sometimes you need to debug a process started by another program.

For example you need a reliable solution and in order to protect against access violations, memory leaks and other barely recoverable stuff, you have a master program and several worker programs. The master program starts the worker program and passes parameters to it. How do you debug a worker program which is not intended to be started by anything except the master program?

You use "attach to process for that".

Typically you do it this way: insert a statement that blocks the worker program for some time - for example, call Sleep() for 15 seconds. Then you kindly ask the master program to start the worker program. When the worker program is started it blocks and you now have 15 seconds to attach to it.

This way you can debug almost any issues - problems at early startup stages, wrong parameters, etc, which you wouldn't reliably reproduce with "run with debugging".

sharptooth
+1  A: 

Start debugging from VS launches an instance of the VS webserver and attaches the debugger to it.

Attach to process allows you to attach to any process and debug it, usually you'd do this to your instance of w3wp.exe running your code in IIS

Andrew Bullock
+1  A: 

Attaching to a process is useful if you don't want to debug right from starting the process. For example, debugging usually slows down execution, so it can be quicker to start the app, get it to a state where a bug appears, and then attach a debugger.

It's also useful if you already have an external means of launching the process that you don't want or can't to import into the IDE.

mdma
+1  A: 

Attach to process is mostly used when you can't run the application from Visual Studio.

For example, if it's a service or if it is a process that has run for a long time and now you want to start debugging it.

Sometimes you also want to debug a remote process, not on your machine - and you can do that using attach to process.

brickner