Debug a Windows Service

Problem

You want to debug a Windows service in Visual Studio .NET (watch debug messages, use variable watches and breakpoints, and so on).

Solution

Start the Windows service through the SCM as you would ordinarily, and attach the Visual Studio .NET debugger manually.

Discussion

You can’t run a Windows service from the Visual Studio .NET integrated development environment (IDE) because Windows services can be executed only by the SCM. However, you can start the Windows service through the SCM, and then attach the debugger.

To debug a Windows service, follow these steps:

  1. Load the source code for the project into Visual Studio .NET.

  2. Install the service if necessary, and then start it using the Computer Management console. (See recipe ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.