How to use timer in VB.NET

1 Answer

0 votes
Imports System
Imports System.Timers

Public Class Program
    Public Shared Sub Main(ByVal args As String())
        Dim timer As Timer = New Timer()
        
		AddHandler timer.Elapsed, New ElapsedEventHandler(AddressOf _Event)
        timer.Interval = 3000
        timer.Enabled = True

		Dim input As String = "x"c
        Console.WriteLine("Press 'q' to quit")
		While (input <> "q"c)
             input = Console.ReadLine()
        End While

        timer.Stop()
        timer.Dispose()
    End Sub

    Private Shared Sub _Event(ByVal source As Object, ByVal e As ElapsedEventArgs)
        Console.WriteLine("3 second count")
    End Sub
End Class





' run:
'
' Press 'q' to quit
' 3 second count
' 3 second count
' 3 second count
' 3 second count
'

 



answered Aug 2, 2022 by avibootz
...