Windows Services – Debugging Trick

I’ve been writing a windows service in VS 2005 for a client and wanted a slick way of debugging it without having to change the code to much.

What I came up with is probably not an original idea but I like it enough I thought I would share it.

Protected Overrides Sub OnStart(ByVal args() As String)
#If DEBUG Then
#End If
End Sub

This causes the Visual Studio debug window to pop up and ask you which VS session to debug from when the service starts and allows you to debug it till your hearts content.