Jump to content

Calling a function every ten minutes


Rob
 Share

Recommended Posts

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?

Link to comment
Share on other sites

  • Moderators

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

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.

Link to comment
Share on other sites

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

Link to comment
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.

Link to comment
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

Link to comment
Share on other sites

  • Moderators

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

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Moderators

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.

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.

Link to comment
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

Link to comment
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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...