How can we use timer control in VB.Net Console Application?
I am trying to use a Timer control in my console application.
Friend WithEvents XTIMER As System.Windows.Forms.Timer
I am setting all its properties. I have set the interval to 15000 ms. But even when I set the Enabled state of the timer control to be true, the tick event is n开发者_开发知识库ot firing. Can any one help me out please?
Module Module1
Sub Main()
aTimer.AutoReset = True
aTimer.Interval = 2000 '2 seconds
AddHandler aTimer.Elapsed, AddressOf tick
aTimer.Start()
Console.ReadKey()
End Sub
Dim aTimer As New System.Timers.Timer
Private Sub tick(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)
Console.WriteLine("tick")
End Sub
End Module
Use the Timer Class
Use System.Timers.Timer instead. Here's a very good comparison of the timer classes.
Import the System.Windows.Forms
reference and use the Timer
class.
精彩评论