Rants, rambles, news and notes from another geek

Even More Debugging Windows Services

Patrick Winfield writes:

_1. If you do this: _

_#if DEBUG bool _running = false; #else bool _running = true; #endif _

_Then you can start your service. Attach to the process with the debugger. Then pause and then un-pause your service. This way the meat of your code doesn’t start to run until your ready to step thru with your debugger. _

_2. You can attach the debugger to the NUnit GUI after it has loaded your service. So if your writing test first then you can place your breakpoints then push the run button. _

Good to hear from you. Patrick is very right on both counts. Unfortunately in the case that caused my original post, I was working with older code that didn’t have any unit tests and I just had to debug one little problem.

When I do test-driven development with services (with almost everything in fact), I try not to put any code at all into the outward facing assembly. So for a windows service I don’t like to put the real code in the EXE’s assembly. I prefer to put it in a separate DLL class library which I can easily test using the techniques discussed in my paper.

Thanks Pat!