Results 1 to 7 of 7

Thread: Time delay in loop

  1. #1

    Thread Starter
    Member
    Join Date
    May 2005
    Posts
    63

    Time delay in loop

    Time delay in loop

    Hello

    I am trying to put a 5 seconds time delay into a loop.

    The following code isn't working.

    Any ideas, please?

    Thank you.

    [CUT-DOWN CODE]

    Code:
     Public theshowresultstimer As New System.Timers.Timer(5000)
    
    do
    
    Beep()
    
    Me.theshowresultstimer.Start()
    
    Beep()
    
    
    loop while....

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Time delay in loop

    Thread.Sleep(500)

  3. #3

    Thread Starter
    Member
    Join Date
    May 2005
    Posts
    63

    Re: Time delay in loop

    Cor, mendhak. That was quick!

    Just out of curiosity, is there any way to do this without stopping the entire thread?

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Time delay in loop

    Isn't that what you wanted? Can you elaborate?

  5. #5
    Frenzied Member Zakary's Avatar
    Join Date
    Mar 2005
    Location
    Canada, Quebec, Montreal
    Posts
    1,654

    Re: Time delay in loop

    Quote Originally Posted by mancroft
    Cor, mendhak. That was quick!

    Just out of curiosity, is there any way to do this without stopping the entire thread?

    Well you may do your loop into another thread
    Using VS 2010 on Fw4.0

  6. #6

    Thread Starter
    Member
    Join Date
    May 2005
    Posts
    63

    Re: Time delay in loop

    Quote Originally Posted by mendhak
    Isn't that what you wanted? Can you elaborate?
    Well, the code below is for another timer (for 45 seconds) but this one fires off a button click and does not appear to stop the entire program.

    What i'd like is something like that but in a loop without a button trigger.

    Code:
    Dim thetimer As New System.Timers.Timer(45000)
    
     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            AddHandler thetimer.Elapsed, AddressOf TimerFired
    
    End sub
    
     Public Sub TimerFired(ByVal sender As Object, _
                   ByVal e As System.Timers.ElapsedEventArgs)
    
            Beep()
    
            thetimer.Enabled = False
    
            flag = 2
    
        End Sub

  7. #7
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Time delay in loop

    Why don't you just put the Beep() in the Tick Event of the Timer??? That way the Beep() would fire at every interval of the timer...

    ** Sorry... didnt read your last post.. seems thats what youre doing now...

    You would just put your interval for 5000, for 5 seconds, then you can have a variable that you increment in the Tick event..., like a Counter (declared outside of the timer). Then when that counter is 9 (9*5 = 45), then disable the timer and call the code you need...
    Last edited by gigemboy; Oct 20th, 2005 at 02:39 PM.

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