.NET Tip of The Day
Learn one new .NET trick every day
Login or Join
.NET Tips & Tricks Community RSS

Those who prefer reading this site through RSS now can also subscribe for updates to .NET Tips & Tricks Community.

How to debug Windows Service startup

Actually you can use this trick every time when:

  1. You want to debug a process startup.
  2. You can't run the process by hitting F5 in Visual Studio (for example, Windows Service).

So the problem is that you can't simply attach the Visual Studio debugger to the process as there isn't one to attach to until after you start the process. However, once you start the process if you have a bug such as an exception in the process's initialization you won't get the debugger attached to the process before it's too late.

Calling Debugger.Launch() or Debugger.Break() in your code allow you to debug such problems. This methods pop up the following screen asking you which instance of the debugger it should use to debug the application.

JIT Debugger
4/16/2008
RSS .NET Tip of The Day
Subscribe to receive one tip from the .NET Tips and Tricks Community per day.
Previous Tips of The Day
The best of the .NET Tips & Tricks Community.
.NET Practitioners .NET Tips & Tricks Community
Every .NET practitioner has a trick up in their sleeve. This is the place to share it with other .NET people.
Submit a Tip
Discovered a new trick? Share it with others.
My Tips
Manage tips you authored.