How To debug a Window Service:
- Install your service.
- Start your service, either from Services Control Manager or Server Explorer.
- In Visual Studio, choose Attach to Processes from the Debug menu.
- Click on Show processes from all user
- From the available processes, look for the process created by your service. The process name will be same as the executable file of the service.
- Click on Attach.
- Choosing the appropriate option will bring the application in debug mode.
- Insert breakpoints to debug the service.
- From the service control manager, use different options like start, stop etc. to debug it.
- 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.