NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Timer.Enabled

Gets or sets a value indicating whether the timer is running. The timer is not subject to garbage collection if the value is true.

[Visual Basic]
Overridable Public Property Enabled As Boolean
[C#]
public bool Enabled {virtual get; virtual set;}
[C++]
public: __property virtual bool get_Enabled();
public: __property virtual void set_Enabled(bool);
[JScript]
public function get Enabled() : Boolean;
public function set Enabled(Boolean);

Property Value

true if the timer is currently enabled; otherwise, false.

Example [Visual Basic]

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

See Also

Timer Class | Timer Members | System.WinForms Namespace