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

chronicles

Registered Member
Joined
Jun 13, 2012
Messages
71
Reaction score
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.
 
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.
 
This is vb.net section so i don't know why your posting java code???
 
I am giving you idea not code.
Or you are looking some one who can code for you.
 
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.
 
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!
 
Can you please show me example for the code in vb.net?
 
You must put the webbrowser1.navigate(etc) inside the code the timer runs, not outside (and set the timer to run every 10 seconds).
 
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
 
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

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.
 
Back
Top