开发者

How can we use timer control in VB.Net Console Application?

开发者 https://www.devze.com 2023-01-18 13:56 出处:网络
I am trying to use a Timer control in my console application. Friend WithEvents XTIMER As System.Windows.Forms.Timer

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消