Example of the timer control in VB.net

Goal: This example shows you how to perform a timed action using the timer control. The code below displays a messagebox every 3 seconds.

Instructions: Open a new Windows Forms Application and add a timer to the form from the toolbox. Replace all the automatically generated code in your project with the code below.

Code:

Public Class Form1
 
    'Configure the timer at form load
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Turn on the timer
        Timer1.Enabled = True
        'Set the interval for each timer "tick"
        Timer1.Interval = 3000
    End Sub
 
    'Actions to perform on each timer tick:
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        MessageBox.Show("This messagebox will popup every 3 seconds!", "www.interloper.nl", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Sub
 
End Class