使用 Windows 服务每晚更新数据库 [英] Nightly Update DB with Windows Service
问题描述
我对 Windows 服务很陌生.并且正在尝试创建一个每晚更新数据库的应用程序.
I am very new to the windows services. and am trying to create an application that will update the db nightly.
我已经有了有效的代码(用于更新本身)
i already have the code that works (for the update itself)
但我不知道如何在服务中对其进行编码.
but i can't figure out how to code it within the service.
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
Dim timerDelegate As New TimerCallback(UpdateDB)
serviceTimer = New Timer(timerDelegate, Nothing, 0, 20000)
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
End Sub
据我所知,上面的代码会运行 20 秒,对吗?我该如何编码,让它每天只运行一次......让我们说午夜.
as far as i understand, the above code will rune very 20 seconds, right? how can i code it so it only runs once a day... at let's say midnight.
谢谢!
还是我应该使用网络服务?我可以安排吗?
or should i be using a web service? can i schedule that?
推荐答案
你需要使用 Windows 服务吗?
Do you need to use a windows service?
一种更简单的方法是创建一个控制台应用程序并使用 Windows 调度程序来启动它.
A simpler approach would be to create a console application and use the windows scheduler to launch it.
Windows 服务的安装和调试可能很麻烦,所以我只会在绝对必要时使用它们.
Windows services can be a pain to install and debug so I would only use them when absolutely necessary.
这篇关于使用 Windows 服务每晚更新数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!