jon wear's personal website

Debugging and Windows Service in VB.Net

11 February 2009

Perhaps this is helpful, perhaps not.  I've spent the last 45 min looking over various blog posts and .Net sites trying to find an easy way to debug an NT service.  I kept coming across, install the serivce, start it, attached  a debugger to a process...etc.  I know there is an easy way to do it because I've used it several years ago in .Net 1.1.  I gave up searching and went looking through old source code and found it. 'Tis below:

'****Modified by JWear on 4/12/2006****

Private Sub New()
If Debugger.IsAttached = True Then
' debug code: allows the process to run as a non-service
' will kick off the service start point, but never kill it.
' shut down the debugger to exit
'Open this page for help ' '
Dim service As New YourService
Dim tempargs() As String
'Original Code Below
ServicesToRun = New System.ServiceProcess.ServiceBase() {New YourService}

'Original Code Above
End If

End Sub

I left the page where I got it in the comments, a hat tip to the original site. The page is no longer available.

By Jon Wear

Related articles