1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to make a timer stop and start again? [Help]

Discussion in 'Visual Basic .NET' started by chronicles, Mar 20, 2013.

  1. chronicles

    chronicles Registered Member

    Joined:
    Jun 13, 2012
    Messages:
    71
    Likes Received:
    2
    So i got a timer and it's set to 10 seconds.
    What i'm trying to do is navigate to a site, start the timer for 10 seconds then
    navigate to another site and start the timer for another 10 seconds then
    navigate to another site and so on...

    I tried doing this:
    Timer1.start()
    webbrowser1.navigate(etc)
    Timer1.stop()

    Timer1.start()
    webbrowser1.navigate(etc)
    timer1.stop()

    But this didin't work.. So I had to create a new timer every time i wanted it to wait 10 seconds..
    though i don't want to create hundreds of timers just in order to wait 10 seconds because i know there is a
    easier and better way to do it with 1 timer..

    Ideas?
    Thank you.
     
  2. chronicles

    chronicles Registered Member

    Joined:
    Jun 13, 2012
    Messages:
    71
    Likes Received:
    2
    Anyone???? please answer ;S
     
  3. seriousjoker

    seriousjoker Registered Member

    Joined:
    Feb 12, 2013
    Messages:
    75
    Likes Received:
    33
    Well you can make a function or object timer, depends upon your choice of language and make new instance of that object and call it when ever you want to wait for 10 seconds, try like this in java

    Code:
    long timer0, timer1;
    
                                        timer0 =  System.currentTimeMillis();
    
                                        do{
                                            timer1 = System.currentTimeMillis();
                                        }
                                        while ((timer1 - timer0) < (10 * 1000));
    or simply you can use wait command if it is suitable with your choice of language.
     
  4. chronicles

    chronicles Registered Member

    Joined:
    Jun 13, 2012
    Messages:
    71
    Likes Received:
    2
    This is vb.net section so i don't know why your posting java code???
     
  5. seriousjoker

    seriousjoker Registered Member

    Joined:
    Feb 12, 2013
    Messages:
    75
    Likes Received:
    33
    I am giving you idea not code.
    Or you are looking some one who can code for you.
     
  6. chronicles

    chronicles Registered Member

    Joined:
    Jun 13, 2012
    Messages:
    71
    Likes Received:
    2
    I've come to find the answer because I've tried finding it myself but nothing points it out.
    So I've done my research before asking for the answer.
     
  7. Narrator

    Narrator Power Member

    Joined:
    Oct 5, 2010
    Messages:
    507
    Likes Received:
    396
    Occupation:
    Internet Marketing
    Location:
    /dev/null
    seriousjoker was right but with different code.

    Set the timer interval to 10secs use timer.tick to run the navigate function. No need to stop the timer.

    Cheers!
     
    • Thanks Thanks x 1
  8. chronicles

    chronicles Registered Member

    Joined:
    Jun 13, 2012
    Messages:
    71
    Likes Received:
    2
    Can you please show me example for the code in vb.net?
     
  9. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,148
    You must put the webbrowser1.navigate(etc) inside the code the timer runs, not outside (and set the timer to run every 10 seconds).
     
  10. garthor

    garthor Newbie

    Joined:
    Mar 24, 2013
    Messages:
    48
    Likes Received:
    13
    I personally don't like to use the timer component unless it's mandatory for a given purpose within my application.
    You can just create a function called Wait, do a while loop comparing the starting date and the current date... ex :

    Code:
        Public Sub WaitSeconds(ByVal intSeconds As Integer)
    
    
            Dim dteWait As Date
            dteWait = Now
            Do While (DateDiff(DateInterval.Second, dteWait, Now) <= intSeconds)
                DoEvents()
                Thread.Sleep(10)
            Loop
    
    
        End Sub
    
     
  11. kbrouder

    kbrouder Newbie

    Joined:
    Apr 25, 2013
    Messages:
    20
    Likes Received:
    4
    If you just want to wait 10sec, use Thread.sleep, but I think it takes milleseconds, so it should be Thread.Sleep(10000)
    If you want something to happen every 10 sec, then use a timer, and you need to make an event handler for Timer.Tick, the IDE will make it for you.