#include-once #include Global $g_rfn[1][2] $g_rfn[0][0] = 0 ; ___________________________________________________________________________ ; #FUNCTION# ==================================================================================================================== ; Name ..........: RegisterLoop ; Description ...: Register function so it will run like a child while loop ; Syntax ........: RegisterLoop($FuncName[, $Sleep = 250]) ; Parameters ....: $FuncName - The function to register. ; $Sleep - [optional] what is the sleep in the loop. Default is 250. ; Return values .: None ; @error ; 1 = function is already registered ; 2 = Failed in register the function ; Author ........: gil900 ; Example .......: yes ; =============================================================================================================================== Func RegisterLoop($FuncName,$Sleep = 250) If Array2DSearch($g_rfn,$FuncName,0) > 0 Then Return SetError(1) If Not AdlibRegister($FuncName,$Sleep) Then Return SetError(2) $g_rfn[0][0] += 1 ReDim $g_rfn[$g_rfn[0][0]+1][2] $g_rfn[$g_rfn[0][0]][0] = $FuncName $g_rfn[$g_rfn[0][0]][1] = $Sleep _ArraySort($g_rfn,0,1,0,1) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: UnRegisterLoop ; Description ...: UnRegister a registered function. use this to shut down the selected loop (registered function) ; Syntax ........: UnRegisterLoop($FuncName) ; Parameters ....: $FuncName - the function to unregister ; Return values .: None ; @error: ; 1 = $FuncName is unregistared. ; Author ........: gil900 ; =============================================================================================================================== Func UnRegisterLoop($FuncName) Local $tmp1 = Array2DSearch($g_rfn,$FuncName,0) If $tmp1 <= 0 Then Return SetError(1) _ArrayDelete($g_rfn,$tmp1) $g_rfn[0][0] -= 1 AdlibUnRegister($FuncName) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: WaitWhile ; Description ...: If you want to use sleep in a registered function (loop) that registered with this UDF ; Then in order to avoid from freezing the other loops, you need to use this function as ; an alternative to sleep. ; for example - Instead of using: Sleep(1000) , you need to use WaitWhile('funcname',1000) ; ; ** important: the 'funcname' must be the name of the function that you called from.. ; ; for example: in this case: ; ; Func SomeName() ; .... ; EndFunc ; ; $FuncName need to be 'SomeName' so you call it this way: WaitWhile('SomeName',1000) ; ; Syntax ........: WaitWhile($FuncName, $WaitTime[, $Sleep = 25]) ; Parameters ....: $FuncName - Read the description. ; $WaitTime - How long to wait. ; $Sleep - [optional] how much to sleep while waiting. Default is 25. ; Return values .: None ; @error: ; 1 = $FuncName is unregistared. ; Author ........: gil900 ; Example .......: No ; =============================================================================================================================== Func WaitWhile($FuncName,$WaitTime,$Sleep = 25) Local $WaitTimer = TimerInit(),$aTmp = $g_rfn, _ $tmp1 = Array2DSearch($aTmp,$FuncName,0) If $tmp1 <= 0 Then Return SetError(1) _ArrayDelete($aTmp,$tmp1) $aTmp[0][0] -= 1 ReDim $aTmp[$aTmp[0][0]+1][3] For $a = 1 To $aTmp[0][0] $aTmp[$a][2] = TimerInit() Next ;_ArrayDisplay($aTmp," (Line: "&@ScriptLineNumber&")") Do For $a = 1 To $aTmp[0][0] If TimerDiff($aTmp[$a][2]) < $aTmp[$a][1] Then ContinueLoop Call($aTmp[$a][0]) $aTmp[$a][2] = TimerInit() Next Sleep($Sleep) Until TimerDiff($WaitTimer) >= $WaitTime EndFunc Func Array2DSearch($aArray, $String, $Dimension, $StartIndex = 1, $EndIndex = "") Local $Output = -1, $a If $EndIndex = "" Then $EndIndex = UBound($aArray) - 1 If $StartIndex >= 0 And $StartIndex <= $EndIndex Then For $a = $StartIndex To $EndIndex If $aArray[$a][$Dimension] = $String Then $Output = $a ExitLoop EndIf Next EndIf Return $Output EndFunc ;==>Array2DSearch