A simple timer class written in VB .Net

Imports System.Timers

Public Class TestTimer
Shared _timer As New Timer()
Dim _timerInterval As Integer = 10000 ‘in millisecconds

Public Sub New()
Initialize()
End Sub

Public Sub Initialize()
AddHandler _timer.Elapsed, AddressOf _timer_Elapsed
_timer.Interval = _timerInterval
End Sub

Public Sub _timer_Elapsed(ByVal sender As Object, ByVal e As ElapsedEventArgs)
‘As long as timer is ‘enabled’ this function will be triggered every time interval set (in this case every 10 seconds)
‘do something here
End Sub

Public Sub start()
_timer.Enabled = True
End Sub

Public Sub stopTimer()
_timer.Enabled = False
End Sub

End Class



Tags: