Results 1 to 6 of 6

Thread: Debugging a service

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2022
    Posts
    28

    Debugging a service

    I wrote a service to start a time and check for a serial port. It was installed via InstallUtil and can be seen, started and stopped in services.
    Once started, I turn to the IDE with the code and under Debug, attach the service. This puts the IDE in debug mode.

    Unfortunately, the first lines of code (as follows) never seems to be triggered.
    Code:
        Protected Sub OnStart(ByVal args() As String)
            Timer1.Enabled = True
            'Findport()
        End Sub
    I put break points in the code, on the timer and the sub triggered by the timer, but none ever seem to be triggered.

    Any ideas guys? What am I missing?

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,661

    Re: Debugging a service

    It doesn't stop on those lines because bgy the time you attach to the process, that's already been executed... as to why the code in the timer, or called by the time doesn't stop... don't know. A little surprised to see the use of a Timer there to be honest, because that's usually a componednt that needs to be situated on a Form... so there may actually be something funky in your setup.


    -g
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2022
    Posts
    28

    Re: Debugging a service

    Humm. Ok. I can pull the timer, but I need a way to re-run a test of the ports every few seconds.
    Any ideas of what could be done to do this?

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,661

    Re: Debugging a service

    Look at this article - bit old, but the timers discussed there are still valid as far as I know ... https://learn.microsoft.com/en-us/ar...-class-library
    You'll probably want either System.Timers.Timer or System.Threading.Timer

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Feb 2022
    Posts
    28

    Re: Debugging a service

    Ok, I changed out the form-based timer for a system based timer.
    Code:
    Private WithEvents Timer1 As New System.Timers.Timer() With {.Interval = 1000}
    Code:
        Protected Sub OnStart(ByVal args() As String)
            Timer1.Start()
            Timer1.Enabled = True
            'Findport()
        End Sub
    
        Private Sub Timer1_Tick(sender As Object, e As EventArgs)
            ReceiveSerialData()
        End Sub
    Does this look better? Its still noy triggering or just not beinging displayed as such.
    Last edited by Juliemac57; Jul 26th, 2024 at 10:57 AM.

  6. #6
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,699

    Re: Debugging a service

    Use System.Threading.Timer rather than a standard Timer.

    For setting up to debug, in the following, Debugger.Launch will prompt to debug. This line ScheduleService (non-existing code) would be where you setup the timer and when the timer is triggered do work and reset the timer.

    Code:
    		Protected Overrides Sub OnStart(ByVal args() As String)
    
    #If DEBUG Then
    			Debugger.Launch()
    #End If
    			RequestAdditionalTime(10000)
    
    			ScheduleService()
    
    		End Sub
    See also https://learn.microsoft.com/en-us/ar...ndows-services

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width