Jump to content

A Quick Question (demo), and 2nd theory question


Recommended Posts

Why does this work . . .

AdlibEnable("PushArray", 250)

While 1
    Func2()
    Sleep(10)
WEndoÝ÷ Ø­N¬¢w¡ë'¢Ö®¶­sdFÆ$Væ&ÆRgV÷C´gVæ3"gV÷C²Â¤FÆ$Væ&ÆRgV÷C´gVæ3gV÷C²Â#S ¥vÆR 6ÆVW¥tVæ@

Second:

I have a toggle that I would like to become true 30 seconds after the script executes but it requires data retrieved after the script is running . . .

So I can't make it just sleep for 30 then run. How do I run it once but 30 seconds after the rest of the script is free to run?

Thanks!

Link to comment
Share on other sites

Use _Timer_SetTimer for multiple timers. AdlibEnable retain the last function name called using AdlibEnable and call it, no multiple Adlib functions.

I dont understand how to get this to call a function every x period of time or was this the answer to the second question?. . . . I did read the help on it. It was far too detailed.

Link to comment
Share on other sites

This is part of the main loop from one of my scripts (I could have probably chopped more garbage out of it for the example). The script displays records by date in a listview, and uses a timer for two purposes. First, the check if the date has changed and if the timer is over a half-second, allows the user to scroll through multiple dates (using the buttons) without reloading the entire screen of data for each date in between (the data is pulled from databases on multiple servers and is i/o intensive = slow). The test at the end auto refreshes the data on the screen every 5 minutes (i chopped out the part that allows users to turn off autorefresh, or adjust the interval, and just stuck in 299 for an example).

Anyway, the script functions within the Switch statement, and the external compares use a timer to kick off separate processes at set intervals. Maybe this will be of some help...

$TimerStart = _Timer_Init()
While 1
    $msg = GUIGetMsg()  
    Switch $msg
        Case $Button_Day_Left
            Lock_ListView()
            Setup_Date()
            $TimerStart = _Timer_Init()
        Case $Button_Day_Right
            Lock_ListView()
            Setup_Date()
            $TimerStart = _Timer_Init()
        Case $GUI_EVENT_CLOSE
            Exitloop
    EndSwitch
    
    If $WorkDate <> $WorkDate_Hold And _Timer_Diff($TimerStart) > 500 Then; Manual update
        Build_ListView()
        GUICtrlSetData($Time_Label, $CurrentTime)
        $TimerStart = _Timer_Init()
    EndIf

    If Not ($msg) Then
        $x = 299 - (Int(_Timer_Diff($TimerStart) / 1000))
        $TimerMinsRemaining = Int($x / 60) + 1
        If $TimerMinsRemaining = 0 Then; Autoupdate
            Lock_ListView()
            Build_ListView()
            GUICtrlSetData($Time_Label, $CurrentTime)
            $TimerStart = _Timer_Init()
        EndIf
        If GUICtrlRead($Label_MinsRemaining) <> $TimerMinsRemaining Then
            GUICtrlSetData($Label_MinsRemaining, $TimerMinsRemaining) 
        EndIf
    EndIf
Wend
Exit

Edit: chopped out more unnecessary junk, and typos (as always)

Edited by Spiff59
Link to comment
Share on other sites

This is part of the main loop from one of my scripts (I could have probably chopped more garbage out of it for the example). The script displays records by date in a listview, and uses a timer for two purposes. First, the check if the date has changed and if the timer is over a half-second, allows the user to scroll through multiple dates (using the buttons) without reloading the entire screen of data for each date in between (the data is pulled from databases on multiple servers and is i/o intensive = slow). The test at the end auto refreshes the data on the screen every 5 minutes (i chopped out the part that allows users to turn off autorefresh, or adjust the interval, and just stuck in 299 for an example).

Anyway, the script functions within the Switch statement, and the external compares use a timer to kick off separate processes at set intervals. Maybe this will be of some help...

$TimerStart = _Timer_Init()
While 1
    $msg = GUIGetMsg()  
    Switch $msg
        Case $Button_Day_Left
            Lock_ListView()
            Setup_Date()
            $TimerStart = _Timer_Init()
        Case $Button_Day_Right
            Lock_ListView()
            Setup_Date()
            $TimerStart = _Timer_Init()
        Case $GUI_EVENT_CLOSE
            Exitloop
    EndSwitch
    
    If $WorkDate <> $WorkDate_Hold And _Timer_Diff($TimerStart) > 500 Then; Manual update
        Build_ListView()
        GUICtrlSetData($Time_Label, $CurrentTime)
        $TimerStart = _Timer_Init()
    EndIf

    If Not ($msg) Then
        $x = 299 - (Int(_Timer_Diff($TimerStart) / 1000))
        $TimerMinsRemaining = Int($x / 60) + 1
        If $TimerMinsRemaining = 0 Then; Autoupdate
            Lock_ListView()
            Build_ListView()
            GUICtrlSetData($Time_Label, $CurrentTime)
            $TimerStart = _Timer_Init()
        EndIf
        If GUICtrlRead($Label_MinsRemaining) <> $TimerMinsRemaining Then
            GUICtrlSetData($Label_MinsRemaining, $TimerMinsRemaining) 
        EndIf
    EndIf
Wend
Exit

Edit: chopped out more unnecessary junk, and typos (as always)

Excellent! so . . .

$Func1 = _Timer_Init()
$Func2 = _Timer_Init()
$Func3 = _Timer_Init()

While 1
    If _Timer_Diff(Func1) > 10 Then
        $Func1 = _Timer_Init()
        Func1()
    EndIf
    If _Timer_Diff(Func2) > 250 Then
        $Func2 = _Timer_Init()
        Func2()
    EndIF
    If _Timer_Diff(Func3) = 30000 Then
        Func3() ;don't want to repeat this function.
    EndIF

    ;Sleep(1000)
WEnd

Only question and possible problem . . .

what if the first function takes 30 seconds . . . (no it really doesnt)

will the second function have to wait?

Edit: Changed to = 30000 not >

Edited by Hatcheda
Link to comment
Share on other sites

Yeah, within this one process only one thing is happening at a time, so while a function is being executing, you're no longer looping through your While statement checking timers. If those numbers you have are really what you intend, 10 and 25 milliseconds, then turning your functions into separate scripts and launching them from a control script doesn't seem an option. They'd never even get started before you were kicking them off again.

You might save a few cpu cycles by not executing TimerDiff for Func(3) more than one time. You could cheat and reuse the same variable something like:

$Func1_timer = _Timer_Init()
$Func2_timer = $Func1_timer
$Func3_timer = $Func1_timer

While 1
    If _Timer_Diff($Func1_timer) > 10 Then
        $Func1_timer = _Timer_Init()
        Func1()
    EndIf
    If _Timer_Diff($Func2_timer) > 250 Then
        $Func2_timer = _Timer_Init()
        Func2()
    EndIF
    If $Func3_timer And (_Timer_Diff($Func3_timer) > 30000) Then; If timer3 not 0 and diff > 30000
        $Func3_timer = 0 
        Func3();don't want to repeat this function.
    EndIF

 ;Sleep(1000)
WEnd

Edit: I'm not sure you can assume your script will hit the test for Func3 when the timer is exacty at 30000. It may hit on 29998 and the next time around be at 30006, so the ">" you had at first would be correct, and then disable the test after the function has run.

Edited by Spiff59
Link to comment
Share on other sites

If those numbers you have are really what you intend, 10 and 25 milliseconds, then turning your functions into separate scripts and launching them from a control script doesn't seem an option. They'd never even get started before you were kicking them off again.

How can you do this? could the scripts already be running? and could I pass the info to them?

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