Search This Blog

Debug the Windows Service

As with all other aspects, debugging a Windows Service is different than a normal application. More steps are required to debug a Windows Service. The service cannot be debugged by simply executing it in the development environment as you can with a normal application. The service must first be installed and started, which we covered in the previous section. Once it is started you attach Visual Studio to the running process in order to step through and debug the code. Remember, each change you make to the Windows Service will require you to uninstall and reinstall the service.

Attach to a Running Windows Service

Here are the directions for attaching to a Windows Service in order to debug the application. These instructions assume that you have already installed the Windows Service and it is currently running.

Load the project into Visual Studio
Click on the Debug menu
Click on the Processes menu item
Make sure the Show system processes is selected
Locate your process in the Available Processes list based on the name of your executable and click on it
Click the Attach button
Click OK
Click Close
Set a break point in the timer1_Elapsed method and wait for it to execute

0 comments: