VB.Net Service will not step into timer in debug

B

Beth via .NET 247

I have written a service in VB.Net. I have installed the service using InstallUtil.
I was able to start the service, but once I attach to and try to debug the service it will not step into my Timer1_Elapsed sub.
It will only step through the OnStop Sub when I stop the service. Now I have messed with the program so much it is not even stepping through this.
I have breakpoints set on the onstart, onstop, and Timer1_Elapsed subs as well as other places it is not breaking on anything.

Could someone tell me what I might be doing wrong or give me an example of how to correctly write/debug a service that runs on a timer or something like a timer.

See my code below:
'*************************************************************
Protected Overrides Sub OnStart(ByVal args() As String)
Timer1.Enabled = True
End Sub

Protected Overrides Sub OnStop()
Timer1.Enabled = False
End Sub

Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
Timer1.Enabled = False
Try
Dim mode As String
mode = "GET" 'just during test trying to get this to work
Dim connectstring As String
connectstring = "database=MYDATABASE;server=MYSERVER;uid=USERNAME;pwd=PASSWORD"
SqlConn.ConnectionString = connectstring
SqlConn.Open()
If mode = "GET" Then
Call GetAndProcessFile()
ElseIf mode = "PUT" Then
Call CreateAndPutFile()
End If
Catch exp As Exception
Debug.Write("An Error Occurred: " & exp.ToString())
End Try
End Sub
 
E

Eric Marvets

What version of .NET are you using. I personally found 1.1 to function alot
better when debugging multi-threaded apps.

Try removing all the breakpoints except for the Timer's event.

--
Eric Marvets
Principal Consultant

the bang project

<shameless self promotion>

Email (e-mail address removed) for Information on Our Architecture and
Mentoring Services

</shameless self promotion>
 
E

Eric

You're using the wrong timer. Check your toolbox. I don't remember which
one or the difference, except that I had the same problem, and that was the
reason.


Beth via .NET 247 said:
I have written a service in VB.Net. I have installed the service using InstallUtil.
I was able to start the service, but once I attach to and try to debug the
service it will not step into my Timer1_Elapsed sub.
It will only step through the OnStop Sub when I stop the service. Now I
have messed with the program so much it is not even stepping through this.
I have breakpoints set on the onstart, onstop, and Timer1_Elapsed subs as
well as other places it is not breaking on anything.
Could someone tell me what I might be doing wrong or give me an example of
how to correctly write/debug a service that runs on a timer or something
like a timer.
See my code below:
'*************************************************************
Protected Overrides Sub OnStart(ByVal args() As String)
Timer1.Enabled = True
End Sub

Protected Overrides Sub OnStop()
Timer1.Enabled = False
End Sub

Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top