我正在尝试创建一个窗口。 安装服务后,服务状态停留在"开始"而不是开始或跑步。
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查询。
答案 0 :(得分:0)
请遵循以下代码:
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