我已经在VS2010中创建了一个windows服务。我安装了它,同时运行它,并将startup类型设置为Automatic。我看到它在EventViewer上运行得很好,并且成功地完成了。
但在那之后,我确实看到EventViewer显示了什么,即使工作完成了,它仍然应该检查DB并跳过所有行完成的操作。
那么问题出在哪里呢?
我需要让它在服务中无限循环才能保持运行吗?
就像这样
While (数据库中的行数!= null)?
因为它看起来并不像任务调度程序那样工作!
发布于 2013-06-17 23:28:36
是的,你需要做一个有可能再次破坏它的循环。示例服务(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 Classhttps://stackoverflow.com/questions/17150856
复制相似问题