【发布时间】:2010-02-06 12:12:54
【问题描述】:
我有一个应用程序,它从 Web 数据库中读取一些数据并定期更新本地数据库。每 5 分钟说一次。
这是一个交互式窗口应用程序的形式。但由于这个应用程序必须连续运行,我们决定制作一个 Windows 服务应用程序。
我们在应用程序中使用了计时器,它设置为 5 分钟的间隔,并且在计时器的每个滴答声中,我们都在检查网络更新。
我们在服务中携带了同样的东西。但似乎计时器现在没有运行。以下是服务中的几种方法:
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
消息正确记录在事件日志中 - 当我们启动或停止服务时。但是没有来自计时器功能的消息。我也尝试过调试服务——在 Visual Studio 中使用 Attach To Process..。但即使代码从未在任何刻度函数上中断。
我们不能在服务中使用计时器吗?如果不是,那另一种方式是什么。如果是,这里可能有什么问题?
谢谢 拉胡尔耆那教
【问题讨论】: