Windows Service Threading Timer stops working after a while

Thei

Newcomer
Joined
Aug 9, 2006
Messages
13
Hi all,

I've got a Windows Service that simple writes a record to a database whenever the callback of the timer is triggered (see code below). The strange thing is that after a while the timer callback isn't called anymore (I usually get 10 records in the database). Any ideas?

Code:
Public Class Service1

#Region " Own Functions And Procedures "
    Private Function Insert_Event(ByVal pEvent As String, ByVal pChanged As DateTime) As Boolean
        Try
            Dim db As New dsAutoServiceTableAdapters.sp_event_insertTableAdapter

            db.GetData(pEvent, pChanged)

            db = Nothing

            Return True
        Catch ex As Exception
            Dim strError As String = ex.ToString

            Return False
        End Try
    End Function
#End Region

    Protected Overrides Sub OnStart(ByVal args() As String)
        ' Add code here to start your service. This method should set things
        ' in motion so your service can do its work.

        System.IO.File.AppendAllText("C:\AutoServiceLog.txt", "[" & Now.ToString & "] Service successfully started." & vbNewLine)

        Const intInterval As Integer = 30000 '30 seconds.
        Dim tAutoService As System.Threading.Timer
        Dim tDelegate As System.Threading.TimerCallback = AddressOf EventAction

        tAutoService = New System.Threading.Timer(tDelegate, Me, 0, intInterval)
    End Sub

    Protected Overrides Sub OnStop()
        ' Add code here to perform any tear-down necessary to stop your service.
        System.IO.File.AppendAllText("C:\AutoServiceLog.txt", "[" & Now.ToString & "] Service successfully stopped." & vbNewLine)
    End Sub

    Public Sub EventAction(ByVal sender As Object)
        If Insert_Event("EventAction triggered", Now) = False Then
            System.IO.File.AppendAllText("C:\AutoServiceLog.txt", "[" & Now.ToString & "] Service generated error." & vbNewLine)
        End If
    End Sub
End Class
 
Back
Top