Windows services Windows服务应用程序中未运行计时器
我有一个应用程序,它从web数据库读取一些数据,并定期更新本地数据库。每5分钟说一次 这是一个交互式windows应用程序的形式。但是由于这个应用程序必须连续运行,我们决定制作一个Windows服务应用程序 我们在应用程序中使用计时器,将其设置为5分钟的间隔,在计时器的每一个滴答声中,我们都在检查web更新 我们在服务中也带着同样的东西。但现在计时器似乎没有运行。以下是服务中的几个方法:Windows services Windows服务应用程序中未运行计时器,windows-services,timer,Windows Services,Timer,我有一个应用程序,它从web数据库读取一些数据,并定期更新本地数据库。每5分钟说一次 这是一个交互式windows应用程序的形式。但是由于这个应用程序必须连续运行,我们决定制作一个Windows服务应用程序 我们在应用程序中使用计时器,将其设置为5分钟的间隔,在计时器的每一个滴答声中,我们都在检查web更新 我们在服务中也带着同样的东西。但现在计时器似乎没有运行。以下是服务中的几个方法: Protected Overrides Sub OnStart(ByVal args() As String
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
当我们启动或停止服务时,消息会正确记录在事件日志中。但是没有来自计时器功能的消息。此外,我还尝试调试该服务-使用附加到进程。。在VisualStudio中。但是,即使比代码从来没有打破任何勾号函数
我们不能在服务中使用计时器吗?如果没有,那么另一种方法是什么。如果是,这里可能有什么问题
谢谢
Rahul Jain没有任何东西可以阻止计时器在Windows服务中工作。在我看来,计时器似乎没有配置为自动重置,但如果不知道您使用的计时器(System.Timers.timer?System.Threading.timer?Other?)及其配置方式,就无法确定 关于调试服务,请在OnStart()方法中放入以下代码“编程断点”: 启动服务时,系统将提示您进入调试会话,执行将在此行中断。您可以从那里进行正常调试
System.Diagnostics.Debugger.Break();