Occasionally you will need to start debugging a process that is already running. This has happened to me with ASP.NET applications. Every once in a while some inexplicable internal calamity will occur and I won't be able to start an ASP.NET application in debug mode. Instead of rebooting, which usually resolves the problem, I can start the application without debugging. (Start without Debugging is on the Debug menu immediately following the Start menu.) After starting the application I can then successfully attach to the process and pick up debugging after the fact. The key here is to know which process to attach to. If you are trying to debug a Windows application, you want to attach to the Windows process. If you are trying to debug an ASP.NET application, you can attach to the instance of Internet Explorer. After attaching, the debugger will stop on breakpoints and you can pick up debugging your application. Follow the numbered steps to attach to a running ASP.NET Web application and start debugging after the application is running.
When you perform an action that reaches a line of code with a breakpoint, the VS .NET debugger will break and the context will be switched to your code in VS .NET. (You can use the AttachDebugger.sln Web application to test attaching to a running process.)
Attaching to a running process can be a useful trick when you are hot after a bug and can't start with debugging. Of course, you can restart VS .NET, restart IIS, or even reboot, but sometimes just getting the application started and debugging it will lead you to the problem that prevented starting with the debugger. ![]() |