Subscribe Now: Feed Icon

Wednesday, March 23, 2011

Debugging Tip

Unit tests are good and nice but there comes a time where you must run your application and see if it works. Some programs are more easy to debug: you just mark them as the startup project, add a breakpoint and you are done.

In other places like a web project you need to attach the debugger to the relevant process: w3wp.exe

But when dealing with Windows Service and when that service falls with an exception on startup or it’s running is really fast, you need something else.

That something is the Debugger class, all you have to do is add a using for System.Diagnostics and add the code:

  1. Debugger.Launch();

when next you run your application/service you will get the nice debugger window:


Just choose your debugger and you are done.

This works with all the project types so if you feel like using it with a console application (like I just did) you can.

(My bug was of course forgetting a little “-“ in the parameters for the console application…)


Keywords: C#, debug, windows service

IceRocket Tags: ,,