Andir Centurion

Joined: 21 Dec 2003 Posts: 184 Location: Chicago Area
|
Posted: Apr 15th, 2004 09:04 AM Post subject: Setting up a simple Timer |
|
|
In VB.NET you can define a timer without adding a control to the forms. To do that, simply include the following code:
| Code: |
Public Class ' this should already be defined
Dim WithEvents Timer As System.Timers.Timer
Sub Main() ' or Form_Load
Timer = New System.Timers.Timer(3000) ' set to fire at 3 seconds
Timer.AutoReset = True ' allows the timer to "loop"
Timer.Enabled = True
End Sub
Private Sub Timer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer.Elapsed
' Your code here
' ** To get the time the event was triggered simply query e.SignalTime
End Sub
End Class
|
Edit:
Forgot to add how to delete/stop the timer.
--It's fairly simple to Stop the timer...Timer.Stop()
--And unloading the timer from memory...Timer.Close() _________________ If you happen to see little people sitting on your desk...don't tell anyone or they might think your crazy too. |
|