JoGa Posted January 19, 2013 Share Posted January 19, 2013 Greetings, I'm using AdlibRegister("AdlibFunc", 2000) to run a function every 2 seconds. However, sometimes the func my take longer than the time scecified. To prevent the functions running overlapped, I use 'AdlibUnRegister("AdlibFunc")' as the first statement in "AdlibFunc". This appears not to work as I expect. Below is a model of the problem Code: #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Proc1Form1", 309, 158, 353, 167) $Label1 = GUICtrlCreateLabel("Label1", 32, 24, 100, 30) GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Opt("GUIOnEventMode", 1) ; Change to OnEvent mode GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_checkGUI") AdlibFunc() $CNT = 0 while(true) $CNT += 1 GUICtrlSetData($Label1, "CNT=" &$CNT) Sleep(100) wend Func GUI_checkGUI() Local $tab, $msg If (@GUI_CTRLID = $GUI_EVENT_CLOSE) Then exit EndIf EndFunc Func AdlibFunc() AdlibUnRegister() GUICtrlSetData($Label1, "XXXX") Sleep(3000) AdlibRegister("AdlibFunc", 2000) EndFunc Any hints? JO Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 19, 2013 Moderators Share Posted January 19, 2013 JoGa,I think I have seen this before where reregistering the Adlib function with the same time delay uses the same timing counter and so it fires again instantly if it has been longer than that period even though it was unregistered for a period. I tried re-registering the function with a different delay to see if that reset the timing counter but it does not appear to do so:#include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) ; Change to OnEvent mode $Form1 = GUICreate("Proc1Form1", 309, 158, 353, 167) GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_checkGUI") $Label1 = GUICtrlCreateLabel("Label1", 32, 24, 100, 30) GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif") GUISetState(@SW_SHOW) AdlibRegister("AdlibFunc", 2000) ConsoleWrite("Registered initially at " & @SEC & @CRLF) $CNT = 0 While (True) $CNT += 1 GUICtrlSetData($Label1, "CNT=" & $CNT) Sleep(100) WEnd Func GUI_checkGUI() If (@GUI_CtrlId = $GUI_EVENT_CLOSE) Then Exit EndFunc ;==>GUI_checkGUI Func AdlibFunc() AdlibRegister("AdlibFunc", 100000) ConsoleWrite("Long registered at " & @SEC & @CRLF) GUICtrlSetData($Label1, "XXXX") Sleep(3000) AdlibRegister("AdlibFunc", 2000) ConsoleWrite("Re-registered at " & @SEC & @CRLF) EndFunc ;==>AdlibFuncSo I suggest you use the Adlib function to check a timer if a flag is set like this:expandcollapse popup#include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) ; Change to OnEvent mode ; This is a flag to show whether we should check the timer or not Global $fCheck_Timer = True $Form1 = GUICreate("Proc1Form1", 309, 158, 353, 167) GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_checkGUI") $Label1 = GUICtrlCreateLabel("Label1", 32, 24, 100, 30) GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif") GUISetState(@SW_SHOW) ; Set teh initial timestamp $iBegin = TimerInit() ConsoleWrite("Beginning at " & @SEC & @CRLF) ; Start the Adlib function AdlibRegister("AdlibFunc", 2000) $CNT = 0 While (True) $CNT += 1 GUICtrlSetData($Label1, "CNT=" & $CNT) Sleep(100) WEnd Func GUI_checkGUI() If (@GUI_CtrlId = $GUI_EVENT_CLOSE) Then Exit EndFunc ;==>GUI_checkGUI Func AdlibFunc() ; Should we check the timer? If $fCheck_Timer Then ; Have we waited 2 secs If TimerDiff($iBegin) > 2000 Then ; Prevent any checking while the function runs $fCheck_Timer = False ConsoleWrite("Waiting at " & @SEC & @CRLF) GUICtrlSetData($Label1, "XXXX") Sleep(3000) ; Allow checking again $fCheck_Timer = True ConsoleWrite("Beginning again at " & @SEC & @CRLF) ; Reset the timestamp $iBegin = Timerinit() EndIf EndIf EndFunc ;==>AdlibFuncThat does what I think you want - am I right? Please ask if you have any questions. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
JoGa Posted January 19, 2013 Author Share Posted January 19, 2013 Thanks M23, that was fast! And it does exactly what I want to do. Jo Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 19, 2013 Moderators Share Posted January 19, 2013 JoGa, Glad I could help. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now