Schleife mit sleep() ist träge

  • Hallo zusammen,

    ich programmiere schon seit längerem mit AutoIt und habe in diesem und anderen Foren schon oft Informationen gefunden. Bei diesem Thema suche ich schon länger, finde aber nirgends eine Lösung.

    Ich versuche mich an einem Tool, das eine Schleife darstellt und - sofern nicht beendet - im Sekundenrythmus Dinge prüfen und protokollieren soll. Das klappt auch bis auf das Programmende. Wenn ich auf beenden gehe dauert es teils 20-30 Sekunden bis das Programm darauf reagiert. Ich vermute, daß der Sleep-Befehl die Ursache ist und während dieser Zeit GUIMSG auflaufen, die erst noch bearbeitet werden. Das würde ich aber gerne abstellen.

    Der beigefügte Quellcode stammt aus der Online-Hilfe des Befehls GUIGetMSG() und ist nur um einen Schleifenzähler und besagten sleep() erweitert.


    Es wäre super, wenn ihr eine Idee hättet, die das Problem löst.

    Günther


    #include <GUIConstantsEx.au3>

    Example()

    ;-------------------------------------------------------------------------------------
    ; Example - Press the button to see the value of the radio boxes
    ; The script also detects state changes (closed/minimized/timeouts, etc).
    Func Example()
    Local $button_1, $radio_1, $radio_3
    Local $radioval1, $msg, $i

    Opt("GUICoordMode", 1)
    GUICreate("Radio Box Demo", 400, 280)

    ; Create the controls
    $button_1 = GUICtrlCreateButton("B&utton 1", 30, 20, 120, 40)
    GUICtrlCreateGroup("Group 1", 30, 90, 165, 160)
    GUIStartGroup()
    $radio_1 = GUICtrlCreateRadio("Radio &0", 50, 120, 70, 20)
    GUICtrlCreateRadio("Radio &1", 50, 150, 60, 20)
    $radio_3 = GUICtrlCreateRadio("Radio &2", 50, 180, 60, 20)

    ; Init our vars that we will use to keep track of GUI events
    $radioval1 = 0 ; We will assume 0 = first radio button selected, 2 = last button
    $i = 1

    ; Show the GUI
    GUISetState()

    ; In this message loop we use variables to keep track of changes to the radios, another
    ; way would be to use GUICtrlRead() at the end to read in the state of each control
    While 1
    $msg = GUIGetMsg()
    $i = $i + 1
    GUICtrlSetData($button_1, "button " & $i)
    Select
    Case $msg = $GUI_EVENT_CLOSE
    MsgBox(0, "", "Dialog was closed")
    Exit
    Case $msg = $GUI_EVENT_MINIMIZE
    MsgBox(0, "", "Dialog minimized", 2)
    Case $msg = $GUI_EVENT_MAXIMIZE
    MsgBox(0, "", "Dialog restored", 2)

    Case $msg = $button_1
    MsgBox(0, "Default button clicked", "Radio " & $radioval1)

    Case $msg >= $radio_1 And $msg <= $radio_3
    $radioval1 = $msg - $radio_1

    EndSelect
    sleep(1000)
    WEnd
    EndFunc ;==>Example

    Einmal editiert, zuletzt von gleicht (3. Dezember 2012 um 13:27)

  • Das kannst du so lösen:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Example()

    [/autoit] [autoit][/autoit] [autoit]

    ;-------------------------------------------------------------------------------------
    ; Example - Press the button to see the value of the radio boxes
    ; The script also detects state changes (closed/minimized/timeouts, etc).
    Func Example()
    Local $button_1, $radio_1, $radio_3
    Local $radioval1, $msg, $i

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUICoordMode", 1)
    GUICreate("Radio Box Demo", 400, 280)

    [/autoit] [autoit][/autoit] [autoit]

    ; Create the controls
    $button_1 = GUICtrlCreateButton("B&utton 1", 30, 20, 120, 40)
    GUICtrlCreateGroup("Group 1", 30, 90, 165, 160)
    GUIStartGroup()
    $radio_1 = GUICtrlCreateRadio("Radio &0", 50, 120, 70, 20)
    GUICtrlCreateRadio("Radio &1", 50, 150, 60, 20)
    $radio_3 = GUICtrlCreateRadio("Radio &2", 50, 180, 60, 20)

    [/autoit] [autoit][/autoit] [autoit]

    ; Init our vars that we will use to keep track of GUI events
    $radioval1 = 0 ; We will assume 0 = first radio button selected, 2 = last button
    $i = 1

    [/autoit] [autoit][/autoit] [autoit]

    ; Show the GUI
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    ; In this message loop we use variables to keep track of changes to the radios, another
    ; way would be to use GUICtrlRead() at the end to read in the state of each control
    $iStart = TimerInit()
    While 1
    $msg = GUIGetMsg()
    If TimerDiff($iStart) >= 1000 Then
    $i = $i + 1
    GUICtrlSetData($button_1, "button " & $i)
    $iStart = TimerInit()
    EndIf
    Select
    Case $msg = $GUI_EVENT_CLOSE
    MsgBox(0, "", "Dialog was closed")
    Exit
    Case $msg = $GUI_EVENT_MINIMIZE
    MsgBox(0, "", "Dialog minimized", 2)
    Case $msg = $GUI_EVENT_MAXIMIZE
    MsgBox(0, "", "Dialog restored", 2)

    [/autoit] [autoit][/autoit] [autoit]

    Case $msg = $button_1
    MsgBox(0, "Default button clicked", "Radio " & $radioval1)

    [/autoit] [autoit][/autoit] [autoit]

    Case $msg >= $radio_1 And $msg <= $radio_3
    $radioval1 = $msg - $radio_1

    [/autoit] [autoit][/autoit] [autoit]

    EndSelect
    ;Sleep(1000) hat in einem Loop mit GuiGetMsg nihts zu suchen
    WEnd
    EndFunc ;==>Example

    [/autoit]

    mfg autoBert

  • Noch einfacher kannst du das mit AdLibRegister lösen. ;)

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Local $button_1, $radio_1, $radio_3
    Local $radioval1, $msg, $i

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUICoordMode", 1)
    GUICreate("Radio Box Demo", 400, 280)

    [/autoit] [autoit][/autoit] [autoit]

    ; Create the controls
    $button_1 = GUICtrlCreateButton("B&utton 1", 30, 20, 120, 40)
    GUICtrlCreateGroup("Group 1", 30, 90, 165, 160)
    GUIStartGroup()
    $radio_1 = GUICtrlCreateRadio("Radio &0", 50, 120, 70, 20)
    GUICtrlCreateRadio("Radio &1", 50, 150, 60, 20)
    $radio_3 = GUICtrlCreateRadio("Radio &2", 50, 180, 60, 20)

    [/autoit] [autoit][/autoit] [autoit]

    ; Init our vars that we will use to keep track of GUI events
    $radioval1 = 0 ; We will assume 0 = first radio button selected, 2 = last button
    $i = 1

    [/autoit] [autoit][/autoit] [autoit]

    ; Show the GUI
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    ; In this message loop we use variables to keep track of changes to the radios, another
    ; way would be to use GUICtrlRead() at the end to read in the state of each control

    [/autoit] [autoit][/autoit] [autoit]

    AdlibRegister("_ActualButton", 1000)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $msg = GUIGetMsg()

    [/autoit] [autoit][/autoit] [autoit]

    Select
    Case $msg = $GUI_EVENT_CLOSE
    MsgBox(0, "", "Dialog was closed")
    Exit
    Case $msg = $GUI_EVENT_MINIMIZE
    MsgBox(0, "", "Dialog minimized", 2)
    Case $msg = $GUI_EVENT_MAXIMIZE
    MsgBox(0, "", "Dialog restored", 2)

    [/autoit] [autoit][/autoit] [autoit]

    Case $msg = $button_1
    MsgBox(0, "Default button clicked", "Radio " & $radioval1)

    [/autoit] [autoit][/autoit] [autoit]

    Case $msg >= $radio_1 And $msg <= $radio_3
    $radioval1 = $msg - $radio_1

    [/autoit] [autoit][/autoit] [autoit]

    EndSelect
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _ActualButton()
    $i += 1
    GUICtrlSetData($button_1, "Button " & $i)
    EndFunc ;==>_ActualButton

    [/autoit]

    lg chess

  • Hallo Chesstiger,

    dein Tip mit AdLibRegister war genau das was ich gesucht habe.

    Vielen Dank für die schnelle Hilfe

    Gleicht