Rajdeep
Rajdeep

Reputation: 493

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 not firing. Can any one help me out please?

Upvotes: 6

Views: 45092

Answers (4)

dbasnett
dbasnett

Reputation: 11773

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

Upvotes: 13

Alex Essilfie
Alex Essilfie

Reputation: 12613

Import the System.Windows.Forms reference and use the Timer class.

Upvotes: 0

Mohamad Alhamoud
Mohamad Alhamoud

Reputation: 4929

Use the Timer Class

Upvotes: 2

Tom Juergens
Tom Juergens

Reputation: 4592

Use System.Timers.Timer instead. Here's a very good comparison of the timer classes.

Upvotes: 1

Related Questions