
Debug a Running Process #41
Chapter 5, Debugging
|
163
HACK
In Windows Server 2003, you can have multiple application
pools; each of these application pools has its own worker
process or worker processes. All of these processes will be
named w3wp.exe. This makes attaching to the right process
somewhat difficult. Once you have identified the correct pro-
cess based on trial and error, you can recognize it based on
its ID.
Connecting to ASP.NET in this way gives you several advantages. You can
start debugging without reinitializing the application and thus losing any in-
process session or cache information. It’s also faster—by attaching to the
process, you don’t have to wait for the browser to start or navigate back to
where you were in the application. When a bug is discovered, you can sim-
ply attach to the process, place your breakpoints, and refresh the browser
window to start the debugging session.
Special Considerations for Services
If you find yourself writing Windows services the only way to debug your
service is by attaching. Simply ensure that the Show System Processes check-
box is checked, and attach to your service.
However, you will find it to be practically impossible to debug the Start
event of the service. The only way to really debug this event is to put a call
to
System.Threading.Thread.Sleep(1000) in the beginning of the Start event
to give you time to attach the debugger. This should ...