February 28, 2021
Hot Topics:

Creating a Windows Service in .NET

  • By Mark Strawmyer
  • Send Email »
  • More Articles »

Debug the Windows Service

Debugging a Windows Service is different than debugging a normal application. More steps are required to debug a Windows Service. While you can debug a standard application in the development environment, this is not the case with a Windows Service. First, the service must be installed and started, which was covered in the previous section. Once it is started you attach Microsoft 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.

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


You should now have a rough idea of what windows services are, how to create, install, and debug them. There is additional functionality with Windows Services that you can explore. This functionality includes the capability to pause (OnPause) and resume (OnContinue). The ability to pause and resume are not enabled by default and are setup through the Windows Service properties.

About the Author

Mark Strawmyer, MCSD, MCSE (NT4/W2K), MCDBA is a Senior Architect of .NET applications for large and mid-size organizations. Mark is a technology leader with Crowe Chizek in Indianapolis, Indiana. He specializes in architecture, design and development of Microsoft-based solutions. You can reach Mark at mstrawmyer@crowechizek.com.

# # #

Page 3 of 3

This article was originally published on April 2, 2003

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date