Plunging into .NET Development

Weblog Pieter Gheysens
Microsoft .NET Development - C# - Enterprise Library - Visual Studio 2005 Team System - Compuware DevPartner - ...
 


Friday, June 23

Debug Windows Service in Visual Studio .NET

Windows services don't actually run directly within the IDE of Visual Studio .NET. There are however a few possibilities to debug them. You can for example install and start the Windows Service and attach a debugger to it. But there's another very straightforward solution ...

When you create a new Windows Service Project in Visual Studio (C#), you get the following main method (main entry point for the process) :



The magic is to use a conditional directive (#if (DEBUG)). Just set up your service, call your initialization method and let the main method sleep infinitively. Start (F5) to fire up your service and stop to kill it - like other runnable projects. It's that simple for debugging your Windows Service! Everything will still work in release as before without changing your code.


4 Comments:

Post a Comment

<< Home