Timers
  Get timer events

Get URL for this page

How Do I...Get timer events without message pump?

Timer allows you to raise an event on a specified interval. This sample illustrates how to use a Timer to raise an event every 1000 milliseconds. Run the sample and observe a new "Hello World" message being printed every second. In its simplest form, using a Timer involves:
  1. Creating a new instance of Timer:

    
    Dim aTimer As System.Timers.Timer = New System.Timers.Timer()
    
    VB

  2. Specifying the event handler:

    
    AddHandler aTimer.Tick, AddressOf OnTimer
    
    VB

  3. Specifying how often to raise the event:

    
    aTimer.Interval = 1000
    
    VB

  4. Enabling the component:

    
    aTimer.Enabled = True
    
    VB

  5. Handling the event:

    
    Public Shared Sub OnTimer(ByVal source As Object, ByVal e As EventArgs)
        Console.WriteLine("Hello World!")
    End Sub
    
    VB

Example

 
VB Timer.exe

[Run Sample] | [View Source]


Copyright 2001 Microsoft Corporation. All rights reserved.