Debugging Windows Services

As seen on Peter Provost's Geek Noise

I have to say that debugging Windows Services in VS.NET is certainly much easier than it was in VC++, but I still wish it was easier. If you need to do it, here are a few tricks:

I had a similar list with one addition, adding a Thread.Sleep(10000); in the OnStart method inside a #if DEBUG so I had time to attach the debugger. I think this is the only way to really debug startup code.

Recently I've found a better way to deal with services, first I create a console project that has nothing but a little startup and shoutdown code. Then I create a "library" project that has the real meat of the service. Once I have everything to my liking I create a windows service project and installer/deployment project in the same solution as the console and library projects. The console project remains the startup project for the solution, but the installer uses the primary output from the service project.

The benefits are that debugging during development is trivial, it forces you to seperate the real functionality from the "host", the final transition to a service is trivial.

Published Thursday, April 03, 2003 6:50 PM by iclemartin
Filed under:

Comments

# Great tips for debugging services : CSharpener's Blog

Great tips for debugging services : CSharpener's Blog

Thursday, April 03, 2003 9:50 PM by TrackBack

# Debugging onStart for a Windows Service : Loosely Coupled

Debugging onStart for a Windows Service : Loosely Coupled

Thursday, April 03, 2003 9:50 PM by TrackBack

# re: Debugging Windows Services

Thats precisely the method I arrived at and it works really well.

Thursday, April 10, 2003 3:52 AM by Kevin

# re: Debugging Windows Services

I'm finding that more and more of my 'application' code actually lives in a library and the application itself just wires the objects together and sets it going... Obviously easier if the app doesnt have a gui... Anyway, I find it makes for much more testable code.

Wednesday, July 09, 2003 11:06 AM by Len Holgate

Leave a Comment

(required) 
(required) 
(optional)
(required)