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.