Sign in to follow this  
Followers 0
Rob

Calling a function every ten minutes

14 posts in this topic

I have a script that uses multiple functions. The first function is very simple bit of code that I want to be called only once every ten minutes. I don't know how to do this because when I put sleep(600000), it doesn't sleep just the that specific function for ten minutes, it pauses the entire script. Is it possible to pause one function for a certain amount of time while the rest of the script goes as normal?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Does this help or give an idea?

Func One()
    $Timer_One = TimerInit()
    While 1
   ;rest of my script
        If TimerDiff($Timer_One) >= (60000) Then
            ExitLoop
        EndIf
    WEnd
    Two()
EndFunc

Func Two()
    $Timer_Two = TimerInit()
    While 1
   ;rest of my script
        If TimerDiff($Timer_Two) >= (60000) Then
            ExitLoop
        EndIf
    WEnd
    One()
EndFunc

Edit: I had it exiting without going to the next function and doing it if it were less than ! B)

Edited by ronsrules

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

i prefer a little more like this

Dim $Timer_One
One()

While 1
    
    If TimerDiff($Timer_One) >= (1000 * 60 * 10) Then
            One()
    EndIf
    Sleep(20)
 WEnd        

    
Func One()
    MsgBox(0,"function called", "will run again in 10 minutes   ")
    $Timer_One = TimerInit()
EndFunc

then the whole script can continue

@ronrules

If TimerDiff($Timer_One) <= (60000) Then

should be ">="

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

I would do this, less code:

Func One()
    $Timer_One = TimerInit()
    While 1
    MainProgram()
        If TimerDiff($Timer_One) <= (60000) Then
            ExitLoop
        EndIf
    WEnd
    Two()
EndFunc

Func Two()
    $Timer_Two = TimerInit()
    While 1
    MainProgram()
        If TimerDiff($Timer_Two) <= (60000) Then
            ExitLoop
        EndIf
    WEnd
    One()
EndFunc

Func MainProgram()
...
EndFunc

But both would work the same

Felix N.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Valuater, shouldn't yours be like this?:

[Edit] Lol, never mind, me being dumb again B)

Edited by Felix N.

Share this post


Link to post
Share on other sites

I would do this, less code:

Func One()
    $Timer_One = TimerInit()
    While 1
    MainProgram()
        If TimerDiff($Timer_One) <= (60000) Then
            ExitLoop
        EndIf
    WEnd
    Two()
EndFunc

Func Two()
    $Timer_Two = TimerInit()
    While 1
    MainProgram()
        If TimerDiff($Timer_Two) <= (60000) Then
            ExitLoop
        EndIf
    WEnd
    One()
EndFunc

Func MainProgram()
...
EndFunc

But both would work the same

Felix N.

i dont think thats good to call more than 1 function from within functions

and the main code becomes secondary to a 10 minute wait for one function

8)

and

">="


NEWHeader1.png

Share this post


Link to post
Share on other sites

Yeh.. Val.. Thanks for noticing my short comming, I edited it before you posted B)


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Valuater, shouldn't yours be like this?:

[Edit] Lol, never mind, me being dumb again B)

no you took out the dim that is needed and the function is called to initiate the time right after you initiated the time

example

hey... you moved the script..

oh...ok

8)

edit

it works... the message box just poped-up with 10 minutes past

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

Val has a good one if he's only ever using the main while. I have programs that after leaving the main GUI, then they never return to the main while again, so I coded mine so that if you should ever only use your functions then it would work just as well.

I use this type of timer function often. I haven't had any leaks as long as I exit out of it and into another function. The problem if not careful is not calling the correct function to go to after words which Val's avoids.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

The if statement does not seem to work is there something else that has to be done to initialize the timer

it will start the first function and run it but will not exit the loop to run the second function

Share this post


Link to post
Share on other sites

i kept that script running and every 10 minutes a message box showed up... so

show us your code so we can see the error

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Hmm, I really don't see why this wouldn't work.... this should even work with the stable release..

Just to make it clear:

Dim $Timer_One
One()

While 1
    If TimerDiff($Timer_One) >= (1000 * 60 * 10) Then
            One()
    EndIf
    Sleep(20)
WEnd        

Func One()
    MsgBox(0,"function called", "will run again in 10 minutes")  ;<---------------------
    $Timer_One = TimerInit()
EndFunc

You replace the MsgBox (where the arrow is) with your main code!

Felix

Share this post


Link to post
Share on other sites

Hmm, I really don't see why this wouldn't work.... You replace the MsgBox (where the arrow is) with your main code!

Felix

I think he is having the problem with the second function....

thats why i asked to see his code

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Does AdLibEnable() suit your needs? It is used to declare that some function should be run at some repeated time interval.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0