window - vb.net(services 在启动时停滞),创建 Windows 服务

  显示原文与译文双语对照的内容

我正在尝试创建一个 Windows 。 安装在"开始"中停留的服务的services.the 状态而不是启动或者运行。


 Protected Overrides Sub OnStart(ByVal args() As String)

 LoadSettings()

 Catch ex As Exception
 EventLog1.WriteEntry(ex.Message)
 End Try
End Sub

LoadSettings() 方法,每隔几秒钟将从/到数据库绘制或者抽取数据。


Private Sub LoadSettings()
 Do While 1 = 1
 Dim tStart As New Threading.Thread(AddressOf PumpData)
 tStart.Start()
 tStart.Join(1200000)
 Threading.Thread.Sleep(1000)
 Loop
End Sub

PumpData方法是一些sql查询。

时间: 作者:

遵循以下代码:


Dim delPeriodicalCheck As New TimerCallback(AddressOf PumpData)
Dim objTimer As System.Threading.Timer
Dim dueTime = 1000 '1 Sec, delay start
Dim period = 60000 '1 Min, you may change this value

Protected Overrides Sub OnStart(ByVal args() As String)
objTimer = New System.Threading.Timer(delPeriodicalCheck, Nothing, dueTime,period)
Catch ex As Exception
EventLog1.WriteEntry(ex.Message)
End Try


Private Sub PumpData(ByVal stateInfo As Object)
'Your code
End Sub

作者:
...