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?
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.
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.
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.
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 .
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With