|
-
Aug 5th, 2009, 02:58 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Timer Help
What i'm looking to do is when a certain condition is met, start a timer and after 1 second have some code executed. Any suggestions?
-
Aug 5th, 2009, 03:01 PM
#2
Re: Timer Help
Add the Timer component to your form, set its interval to 1000. When your condition is met enable the timer. Then handle the Timer's Tick event. When the Tick event occurs, run your code then disable the timer.
-
Aug 5th, 2009, 03:01 PM
#3
Member
Re: Timer Help
Is this for a windows form or in general?
You can create a modular level instance of a System.Timers.Timer object and set AutoReset to false so it only executes once.
Example:
Code:
Private WithEvents _mTimer As New System.Timers.Timer
Public Sub Test()
_mTimer.AutoReset = False
_mTimer.Interval = 1000
_mTimer.Start()
End Sub
Private Sub _mTimer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles _mTimer.Elapsed
'Do some stuff
End Sub
There are mixed feelings about this, but if you are in a windows form you can always use a background worker which gives you some cross thread reporting functionality without much code.
-
Aug 5th, 2009, 04:31 PM
#4
Thread Starter
Addicted Member
Re: Timer Help
Thanks for the help I shall try both ways and see which I find better. Its actually for a game which does use a windows form.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|