Hello
I had an application which reads some data from a web database and updates the local database - on a periodic basis. Say every 5 mins.
This was in the form of an interactive windows application. But since this application has to run continuously, we decided to make a Windows Service Application.
We were using timers in the application, which were set to an interval of 5 mins, and in every tick of the timer, we were checking for the web updates.
We have carried the same thing in the service. But it seems the timers are not running now. Following are the few methods from the service:
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.
'connect to sap business one
If Connect("rlap1", "sa", "dracula", "UnimaxNew", "manager", "manager") = False Then
End
SyncEvents.WriteEntry("Unable to connect to SAP Business One, " & oCompany.GetLastErrorDescription, EventLogEntryType.Error)
Else
SyncEvents.WriteEntry("Connected to SAP Business One.", EventLogEntryType.Information)
End If
'start the timers
WebTimer.Start()
SapTimer.Start()
DataTimer.Start()
SyncEvents.WriteEntry("Synchronization process started.")
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
oCompany.Disconnect()
SyncEvents.WriteEntry("Disconnected from SAP Business One.", EventLogEntryType.Information)
'stop the timers
WebTimer.Stop()
SapTimer.Stop()
DataTimer.Stop()
SyncEvents.WriteEntry("Synchronization process stopped.")
End Sub
Private Sub WebTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WebTimer.Tick
SyncEvents.WriteEntry("Checking for new orders.")
CheckOrder()
End Sub
Private Sub SapTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SapTimer.Tick
SyncEvents.WriteEntry("Checking for new deliveries.")
CheckDelivery()
End Sub
Private Sub DataTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataTimer.Tick
SyncEvents.WriteEntry("Checking for stock updates.")
CheckStock()
End Sub
The messages are log correctly in the event logs - when we start or stop the service. But there are no messages from timers function. Also I've tried debugging the service - by using Attach To Process.. in Visual Studio. But even than the code never breaked on any of the tick functions.
Can't we use the timers in the service? If no, than what is the other way. If yes, what could be wrong here?
Thanks Rahul Jain