Home > Articles > Programming > Windows Programming

  • Print
  • + Share This
From the author of

Debugging

Finally, when developing a Windows service, it is important to know how to debug it. Unfortunately, you cannot simply set a break point in the Visual Studio .NET IDE and then hit F5 to start the service. Instead, you must first install the service and start it from the Services MMC or from the Server Explorer in VS .NET. Then, do the following:

  1. Set a break point in a location other than the OnStart event (because the service is already started). A good place would be in the event handler for the timer if using a poling mechanism or in the event that handles the notification from MSMQ or the FileSystemWatcher class.

  2. Click on the Debug/Processes menu. This invokes the Processes dialog box that shows all of the running process on the machine, as shown in Figure 1.

    Figure 1Figure 1 The Processes dialog box.

  3. In the dialog box, click on Show System Processes in order to show the Windows services.

  4. Find the service process in the list and click Attach.

  5. Select Common Language Runtime in the resulting dialog box and click OK.

  6. Click Close.

  7. Wait until the next OnTimer event fires (or the service is notified) and VS .NET will immediately go into break mode. From this point, you can step through the execution of the service class.

This dialog box is invoked from the Debug menu and can be used to attach to a running Windows service.

  • + Share This
  • 🔖 Save To Your Account