Sign in to follow this  
Followers 0
Miliardsto

Timers Crashing

3 posts in this topic

I do my timers like this by clicking checkbox function is called and timer is set up.

There is a trouble cause I got so many Timers, 20 like this below and I can see if they is launched 5 timers program starts freezing and often crashing.

I know it takes memory but is is right way to do timers like that or what should i do?

Case $checkerSS
                If GUICtrlRead($CheckerOne) = 1 Then
                    $ss = _Timer_SetTimer($Form1,4000,"checkScreen")
                Else
                    _Timer_KillTimer ($Form1,$ss)
                EndIf

            Case $checkerPos
                If GUICtrlRead($DiscAlert) = 1 Then
                    $disc = _Timer_SetTimer($Form1,20000,"checkPosition")
                Else
                    _Timer_KillTimer ($Form1,$disc)
                EndIf

            Case $checkerVars
                If GUICtrlRead($AlertPlayerPos) = 1 Then
                    $ap = _Timer_SetTimer($Form1,15000,"checkVars")
                Else
                    _Timer_KillTimer ($Form1,$ap)
                EndIf

 

Share this post


Link to post
Share on other sites



Post a full runable (reproducer) and i will have a look.

Share this post


Link to post
Share on other sites

_Timer_SetTimer is gonna register a lot of callback functions, which could be fine but it seems to be breaking your script. Perhaps some of your functions are overlapping because they're taking too long to finish? If you use TimerInit it's just gonna return an int value that can be used in TimerDiff to get the passed time, no callbacks needed. Instead of registering 20 callbacks you could create 20 variables from TimerInit and keep track of the timers yourself

HotKeySet("{Esc}", Close)

Global $aTimerArray[20][3]

For $i = 0 to 19
    $aTimerArray[$i][0] = TimerInit()           ; Initialize a timer
    $aTimerArray[$i][1] = MyFunc                ; Function to call when timeout hit
    $aTimerArray[$i][2] = Random(1000, 1500, 1) ; Timeout when to call the function in the [$i][1]
Next

While (True)
    For $i = 0 to 19
        ; If the difference between the timer in [$i][0] is greater than the timeout set, call the function stored in [$i][1]
        ; Passing the timer by reference so the MyFunc function resets it automatically, you could also reset it in this if statement
        If (TimerDiff($aTimerArray[$i][0]) > $aTimerArray[$i][2]) Then $aTimerArray[$i][1]($aTimerArray[$i][0])
    Next
    Sleep(100)
WEnd

Func MyFunc(ByRef $iTimer)
    ConsoleWrite("MyFunc called after " & TimerDiff($iTimer) & "ms for this timer" & @LF)
    $iTimer = TimerInit()
EndFunc

Func Close()
    Exit 0
EndFunc

When it finishes calling the function in [$i][1] even if the next timer is WAYYYY over the timeout, it will still call the function and reset the timer and move on.

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

  • Similar Content

    • newcoding
      Generating Unique Combinations From Fixed Data
      By newcoding
      #include <Excel.au3> #include <File.au3> #include <String.au3> #include <Array.au3> Local $sku_array[0] ;13640 Local $name_array[0] ;13640 Local $sku_string Local $name = "Name Here"; hardcoded, iterate through final list Local $name_sku = "E001" ; hardcoded, iterate through final list For $size = 0 to 3 Step 1 For $mg = 0 to 30 Step 1 For $b = 0 to 1 Step 1 For $menthol = 0 to 4 Step 1 For $vg = 0 to 10 Step 1 $sku_string = String($name_sku & $size & $mg & $b & $menthol & $vg) _ArrayAdd($sku_array, $sku_string) _ArrayAdd($name_array, $name) Next Next Next Next Next ;_ArrayDisplay($name_sku_array, "Array Data:") Local $oExcel = _Excel_Open() Local $sWorkbook = @ScriptDir & "\FURLS_TRLM_Product_Listing_Eliquid.xls" Local $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook, Default, Default, True) _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $sku_array, "B2:B13641") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $name_array, "J2:J13641") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $name_array, "A2:A13641") ;A2 or Column 1 - $name_string ;B2 or Column 2 - $sku_string ;J2 or Column 10 - $name_string So I am trying to generate every unique combination using 1 value from each set and then place each generated value into an array and then write to an excel sheet.
      Edit: Functional Code, F#CK THE FDA!
       
      I have the following data sets:
      Size: 10, 30, 50, 100
      MG: 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30  (shortened in the above code for time constraints while testing)
      VG: 0,1,2,3,4,5,6,7,8,9,10
      Boost: 0,1
      Menthol: 0,1,2,3,4
    • afallenhope
      AutoitExe not working on Win 10
      By afallenhope
      Hello all! 
      I am having a bit of trouble and was wondering if anyone may have a workaround for my issue. I made a script that would automatically install a piece of software each night on a Windows 7 Box. Now I have been instructed to do the same with a Windows 10 box since the application is now being tested on Windows 10. 
      The way I did the win7 installation was that I made a script and then made an executable that I call with a batch file along with the Installer. So the process is 
      AutoitMainFile calls batch file, batch file opens Installer, and the automatedinstaller.exe  The automatedinstlaller waits 10-20 seconds to make sure the Installer has been fully loaded.
      When I try to do the same both get loaded but the automatedinstallation.exe does not send commands to the installer. The code does work and nothing from the program we are wanting to install has changed as our Windows 7 runs every night no problem. 
       
      Do I need to make a new automatedinstall script for windows 10? 
      Any advice is appreciated 
      Thanks,
      Richard
    • aa2zz6
      Load program from CMD
      By aa2zz6
      I have a .ini file that holds my path for our mapping software. I can't seem to get the CMD function to read the file path. I removed everything but the file path but it doesn't work.
      [ArcGIS Desktop]
      Path=C:\Users\<user name>\AppData\Local\ESRI\Desktop10.1\Launcher.exe
      Local Const $sFilePath = @ScriptDir & "\Mapping\Path\ " & "Path" & ".ini" Local $sFilewrite = IniWrite($sFilePath, "ArcGIS Desktop", "Path=", "C:\Users\aa2zz6\AppData\Local\ESRI\Desktop10.1\Launcher.exe") Start() Func Start() $MyCommand = $sFilewrite Run(@ComSpec & " /c " & $MyCommand, @SystemDir, @SW_HIDE) EndFunc ;==>Start  
    • aa2zz6
      Include/Calling scripts from sub directories
      By aa2zz6
      I have a folder that holds a main script. In the main folder I have sub folders with scripts that include certain functions. How do I access the scripts in the sub folders.
      I can assume @ScriptDir wouldn't work with include to search the current folder?  
      #Include "file.au3"  
    • ntprohd
      how to login to google with winhttp in AutoIt
      By ntprohd
      how to login to google with winhttp in AutoIt