Gets or sets a value that specifies the time, in milliseconds, between timer ticks.
[Visual Basic] Public Property Interval As Integer [C#] public int Interval {get; set;} [C++] public: __property int get_Interval(); public: __property void set_Interval(int); [JScript] public function get Interval() : int; public function set Interval(int);
The number of milliseconds between each timer tick. The value is not less than 1.
The following example shows a simple interval timer, which sets off an alarm every 3 seconds. When the alarm occurs, a MessageBox displays a count of the number of times the alarm has activated and asks if the user if the timer should continue running.
[Visual Basic]
' CLASS LEVEL DECLARATIONS 'Declare timer, alarm counter and exit flag. Shared myTimer As WinForms.Timer Shared alarmCounter As Integer Shared exitFlag As Boolean 'Run this method when the timer triggers. Shared Sub MyTimerEventProcessor(ByVal myObj As Object, ByVal myEventArgs As EventArgs) myTimer.Stop() If (MessageBox.Show("Alarm went off. Continue running?" , _ "Count = " & alarmCounter, MessageBox.YesNo) = WinForms.DialogResult.Yes) Then 'Continue running the timer. alarmCounter += 1 myTimer.Enabled = True Else exitFlag = False myTimer.Enabled = False End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 'Initialize the alarm counter and exit flag. alarmCounter = 1 exitFlag = False 'Declare an event handler for the timer event. Dim myTimerEventHandler As EventHandler myTimerEventHandler = New EventHandler(AddressOf MyTimerEventProcessor) myTimer.AddOnTimer(myTimerEventHandler) 'Set the timer interval to 3 seconds and start it. myTimer.Interval = 3000 myTimer.Start() 'Run the timer and trigger the event. Do While exitFlag = False Application.DoEvents() Loop End Sub Shared Sub Main() 'Initialize the timer. myTimer = New WinForms.Timer End Sub