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?
Printable View
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?
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.
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:
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.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
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.