Thei Posted August 5, 2008 Posted August 5, 2008 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? 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.