Debugging a Windows Service Startup Method

It’s been a long time since I wrote a Windows service but…I was doing that today and realized that the more things change, the more they stay the same. It would seem that it’s still a painful and problematic process if you want to debug the startup of a custom Windows service you write in Visual Studio.  If you follow the published guidance around this (, it suggests a variety of work-arounds for doing this, but nothing that I would call an out of the box solution.

Well…there IS an out of the box solution.  So even though it may not be rocket science I guess it’s worth sharing.  If you want to break in on the OnStart event of your custom Windows service, just add this line in your code where you want to start debugging:  Debugger.Launch();

Compile your code then install the Windows service.  When you start the service you should see a dialog that asks you if you want to debug the service – like this:

Just say yes and another dialog will pop up where it asks you if you want to start a new instance of Visual Studio, or use an existing instance.  Of course you will have Visual Studio already up and going with your source code for your service loaded and break points set.  Just pick that instance of Visual Studio and – voila’ – you are debugging OnStart.  Old school sometimes works best.  🙂

One thought on “Debugging a Windows Service Startup Method

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s