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
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