Debugging Windows Services in C# and .NET

The compiled executable file that a service application project creates must be installed on the server before the project can function in a meaningful way. You cannot debug or run a service application by pressing F5 or F11; you cannot immediately run a service or step into its code. Instead, you must install and start your service, and then attach a debugger to the service's process.

Here we are going to see how to debug our own windows services.

Steps for debugging windows services:

  1. Install your service. In my case it is the service which I created and installed as mentioned in my previous article i.e. Birthday Wish Scheduler in C#.

  2. Start the service.

  3. Open your project in Visual Studio.NET.

  4. Then choose processes from the Debug menu. The following windows will appear.

  5. Click on "Show system processes".

  6. 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. 

  7. Clicking Attach will show "Attach to Process" dialog box.

  8. Choosing the appropriate option will bring the application in debug mode.

  9. Insert breakpoints to debug the service.

  10. From the service control manager, use different options like start, stop etc. to debug it.

Until next time.....Happy .NETing!