-
Jul 26th, 2024, 07:36 AM
#1
Thread Starter
Junior Member
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?
-
Jul 26th, 2024, 07:48 AM
#2
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
-
Jul 26th, 2024, 08:04 AM
#3
Thread Starter
Junior Member
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?
-
Jul 26th, 2024, 09:59 AM
#4
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
-
Jul 26th, 2024, 10:44 AM
#5
Thread Starter
Junior Member
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.
-
Jul 27th, 2024, 03:41 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|