Results 1 to 4 of 4

Thread: [RESOLVED] Timer Help

  1. #1

    Thread Starter
    Addicted Member mouse88's Avatar
    Join Date
    Mar 2009
    Location
    South Wales, United Kingdom
    Posts
    225

    Resolved [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?

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    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.

  3. #3
    Member sh4de's Avatar
    Join Date
    Aug 2009
    Location
    Irvine, CA
    Posts
    48

    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.

  4. #4

    Thread Starter
    Addicted Member mouse88's Avatar
    Join Date
    Mar 2009
    Location
    South Wales, United Kingdom
    Posts
    225

    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
  •  



Click Here to Expand Forum to Full Width