You can only attach the debugger to a running service. The attachment process interrupts the current functioning of your service; it does not actually stop or pause the service's processing. That is, if your service is running when you begin debugging, it is still technically in the Started state as you debug it, but its processing has been suspended.
How to attach a debugger to a Windows ServiceFirst ensure your service is installed and is running properly by inspecting the Service windows under Control Panel/Administrative Tools. Go to your Visual Studio’s main menu and choose: Debug/Attach process to… (this is available for Visual Studio .NET 2008). From the available processes list, choose the process you want to attach a debugger to. The service’s process will have the same name as the exe file generated by the compiler for that service.
Downsides of attaching a debugger
- You can't debug the OnStart() and Main() methods because you can only attach a debugger to a service after it has started running, which by then, the OnStart() method has already completed its execution and returned the control to the operating system.
- You must attach the debugger each time the project is restarted.
- This feature is not availble for Visual Studio .NET Express Edition