harriyott.com

Tuesday, December 06, 2005

Debugging a service in .NET

To debug a service in .NET, put

System.Diagnostics.Debugger.Break();

in the OnStart method. This will fire up a prompt when run, which is where the debugger can be selected.

3 Comments:

JP said...

I'm trying this, with no luck. The debugger prompt comes up, and I select the running instance of VS2005, which is made the foreground task, but the "breakpoint" is not hit. Any other special considerations I need to know about?

December 08, 2005 2:59 PM  
Simon said...

Not that I'm aware of. Unfortunately I'm not an expert - I found out about it from a Google search, tried it and it just worked. If it's just an example you're trying, could you zip it up and send it to me?

December 08, 2005 5:32 PM  
Simon said...

Ah, worked it out: you have to put a manual breakpoint on the next line of code.

December 22, 2005 11:12 PM  

Post a Comment

Links to this post:

Create a Link

<< Home