在vb.net中创建一个windows服务(服务在启动时卡住)



我正在尝试创建一个窗口。在我安装服务之后。服务的状态卡在"正在启动",而不是已启动或正在运行。

    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

遵循以下代码:

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

相关内容

  • 没有找到相关文章

最新更新