Is there an easier way to step through the code than to start the service through the Windows Service Control Manager and then attaching the debugger to the thread? It’s kind of cumbersome and I’m wondering if there is a more straightforward approach.
Share
If I want to quickly debug the service, I just drop in a
Debugger.Break()in there. When that line is reached, it will drop me back to VS. Don’t forget to remove that line when you are done.UPDATE: As an alternative to
#if DEBUGpragmas, you can also useConditional("DEBUG_SERVICE")attribute.On your
OnStart, just call this method:There, the code will only be enabled during Debug builds. While you’re at it, it might be useful to create a separate Build Configuration for service debugging.