Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vb.net

console

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?

like image 342
Rajdeep Avatar asked Sep 29 '10 09:09

Rajdeep


People also ask

How does timer control work in VB net?

The Timer is a built-in VB.Net control that allows you to execute code after a specific amount of time has elapsed from the moment at which the timer is enabled, or repeatedly at specific time intervals. Once enabled, the timer will generate a Tick event at predetermined intervals.

How do I add a timer in Visual Basic?

Select the Toolbox tab, in the Components category, double-click or drag the Timer component to your form. The timer icon, called timer1, appears in a space below the form. Select the Timer1 icon to select the timer. In the Properties window, select the Properties button to view properties.

What is the use of timer tool in Visual Basic?

The timer is an interesting and useful control in Visual Basic 2015. It can be used to create Visual Basic 2015 applications that are time-related. For example, you can use the timer to create a clock, a stopwatch, a dice, animation and more. Timer is a hidden control at runtime, just like the engine of a car.

What is the use of timer control explain with one example?

The Timer Control allows us to set Interval property in milliseconds (1 second is equal to 1000 milliseconds). For example, if we want to set an interval of two minute we set the value at Interval property as 120000, means 120x1000 .


1 Answers

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
like image 199
dbasnett Avatar answered Sep 21 '22 05:09

dbasnett