Windows service not executing after first run

女生的网名这么多〃 提交于 2019-12-11 14:14:42

问题


I have create a windows service in VS 2010. I install it and also run it at the same time and set startup type to Automatic . I see it running fine through EventViewer and is successfully completed.

But after that i done see EventViewer showing anything, even if the work is doen it still should check DB and skip as all rows done.

So what is the issue ?

DO i need to make it an infinite loop in the service to keep it running?

Something like

While (ROWs in DB ! = null) ?

Because it does not seem it is working like task scheduler!


回答1:


Yes, you need to do a loop with the possibility to break it again. Example service (VB.NET):

Public Class MyService

    Protected Property IsRunning As Boolean = False

    Protected Sub OnStart(args() As String)
        IsRunning = True
        ' make the loop function run asynchronously
        Dim t As New System.Threading.Thread(AddressOf MyLoopFunction)
        t.Start()
    End Sub

    Protected Sub MyLoopFunction
        While IsRunning

            ' here comes your code ...

            ' sleep for a second for better CPU freedom
            System.Threading.Thread.Sleep(1000)
        End While
    End Sub

    Protected Sub OnStop()
        IsRunning = False
    End Sub

End Class


来源:https://stackoverflow.com/questions/17150856/windows-service-not-executing-after-first-run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!