Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » .NET Knowledge Base

Post new topic   Reply to topic
Setting up a simple Timer
View previous topic :: View next topic  
Author Message
Andir
Centurion


Joined: 21 Dec 2003
Posts: 184
Location: Chicago Area

PostPosted: Apr 15th, 2004 09:04 AM    Post subject: Setting up a simple Timer Reply with quote

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » .NET Knowledge Base All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic