我有我在 .NET 中编写的 Windows 服务的这段代码......但是,无论我在 tmrRun 属性中放置的时间间隔如何,TICK 函数都不会被执行。我错过了什么?我确信它是我没有看到的愚蠢的东西。
谢谢你
Imports System.IO
Public Class HealthMonitor
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.
tmrRun.Start()
End Sub
Protected Overrides Sub OnStop()
// Add code here to perform any tear-down necessary to stop your service.
tmrRun.Stop()
End Sub
Private Sub tmrRun_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmrRun.Tick
//DO some stuff
End Sub
End Class
最佳答案
这对我有帮助。
进口系统
导入 System.Timers
公开课 MyTimers
Protected Overrides Sub OnStart(ByVal args() As String)
Dim MyTimer 作为新 System.Timers.Timer()
AddHandler MyTimer.Elapsed, AddressOf OnTimedEvent
' 将间隔设置为 10 秒(10000 毫秒)。
MyTimer.Interval = 10000
MyTimer.Enabled = True
结束子
Private Shared Sub OnTimedEvent(source As Object, e As ElapsedEventArgs)
Console.WriteLine("Hello World!")
结束子
结束类
关于.net - 为什么此计时器不会在 .net 服务应用程序中启动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/983540/