How to Debug Window Service without installing


Usually if we want to debug the windows service application to see if it is behaving as the way you want it to be, what we need to do is by installing the windows service and attaching that project to the process.

There is also another way to debug without installing it, what we need to do to obtain this kind of debugging is to create another project such as console project then copy and paste the code below.

  1.     Sub Main()
  2. #If Not Debug Then
  3.         Dim servicesToRun As System.ServiceProcess.ServiceBase()
  4.  
  5.         servicesToRun = New System.ServiceProcess.ServiceBase() {New MyService()}
  6.         System.ServiceProcess.ServiceBase.Run(servicesToRun)
  7. #Else
  8.         Dim service As AS2Client.AS2SenderService = New MyService()
  9.         service.myentrysub()
  10.  
  11.         System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite)
  12.  
  13. #End If
  14.  
  15.  
  16.        
  17.     End Sub


References:
Run Windows Service as a Console program

Debugging Windows Services under Visual Studio .NET

, , ,

  1. No comments yet.
(will not be published)
Submit Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Subscribe to comments feed
  1. No trackbacks yet.

SetPageWidth