Jump to content
Sign in to follow this  
JoGa

AdlibUnRegister

Recommended Posts

JoGa

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

Share this post


Link to post
Share on other sites
Melba23

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   ;==>AdlibFunc

So I suggest you use the Adlib function to check a timer if a flag is set like this:

#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   ;==>AdlibFunc

That does what I think you want - am I right? Please ask if you have any questions. :)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______Open Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
JoGa

Thanks M23, that was fast! :)

And it does exactly what I want to do.

Jo

Share this post


Link to post
Share on other sites
Melba23

JoGa,

Glad I could help. :)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______Open Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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  

×