## Tuesday, February 2, 2010

### VB2005 Timers

There are several types of timers offered by the .NET Framework. Inside Windows Forms applications, you can use the System.Windows.Forms.Timer control. You can use either the System.Threading.Timer class or the System.Timers.Timer class if your application doesn't have a user interface.
The following is an example that uses the Timer class in the System.Threading namespace to call back a given procedure. After the timer is running, you can change timer values only by means of a Change method, which takes only two arguments, the due time and the period. The Timer object has no Stop method. You stop the timer by calling its Dispose method.
Imports System.Threading
Dim dueTime as New TimeSpan(0,0,1)
Dim period as New TimeSpan(0,0,0,0,500)
Dim t As New Timer(AddressOf TimerProc, Nothing, dueTime, period)
Dim tEn As Boolean = True
Private Sub TimerProc(ByVal state As Object)
If tEn = True Then
'Do timer things
End If
End Sub