Jump to content



Photo

GUIGetMsg .... Infinite event loop with no delay?


  • Please log in to reply
5 replies to this topic

#1 Javik

Javik

    Seeker

  • Active Members
  • 49 posts

Posted 06 March 2012 - 08:07 PM

(This is a noobish question for GUI event monitoring.)


Although this is from the example program for GUIGetMsg(), and it works, it seems like there is a serious problem.

While 1         $msg = GUIGetMsg()         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     WEnd



If there is no GUI activity, the script is basically an infinite loop that runs with no delay.

While 1         $msg = GUIGetMsg()     WEnd


Yet the task manager CPU usage does not jump to 100% when running the program. That seems... odd.

It seems like the program design should be more event driven, so that if nothing is happening the program will sleep. Though apparently there is no such thing as

EventWait until GUIGetMsg()         $msg = GUIGetMsg()         [. . . code goes here to process event . . .] EndEventWait


Is this really the normal programming practice for Windows GUI event loops? It just seems wrong to be using an infinite loop with no idle-time release mechanism.

Edited by Javik, 06 March 2012 - 08:08 PM.






#2 Jos

Jos

    oh joy ...

  • Developers
  • 21,057 posts

Posted 06 March 2012 - 08:10 PM

Have you read the helpfile page about "GUI Concept"?

Visit the SciTE4AutoIt3 Download page for the latest versions                                                                 Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)


#3 Javik

Javik

    Seeker

  • Active Members
  • 49 posts

Posted 06 March 2012 - 08:17 PM

Have you read the helpfile page about "GUI Concept"?


Oh puh-leaze, nobody reads manuals. :oops:

We arrive here with just a vague idea of what we want to do, and hope the specific helpfiles and copied example scripts we're searching for, will provide enough detail to make our hackery work.

Thanks for the guidance.

#4 Jos

Jos

    oh joy ...

  • Developers
  • 21,057 posts

Posted 06 March 2012 - 08:19 PM

Your question was valid and well formulated, but I just had the impression you hadn't read that page yet and believe is gives a good explanations of the fundamentals.
Don't hesitate to ask when things aren't clear yet.

Visit the SciTE4AutoIt3 Download page for the latest versions                                                                 Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)


#5 Javik

Javik

    Seeker

  • Active Members
  • 49 posts

Posted 06 March 2012 - 08:33 PM

(EDIT: I should just read the help files more thoroughly.)

GUIGetMessage


Remarks
This function automatically idles the CPU when required so that it can be safely used in tight loops without hogging all the CPU.


Edited by Javik, 06 March 2012 - 08:40 PM.


#6 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,353 posts

Posted 06 March 2012 - 08:39 PM

Javik,

I assume there must be more going on in the background, either in how the script is compiled or how Windows runs the code

So obviously you did not read the page to which Jos pointed you? :oops:

"Usually a tight loop like the one shown would send the CPU to 100% - fortunately the GUIGetMsg function automatically idles the CPU when there are no events waiting. Do not put a manual sleep in the loop for fear of stressing the CPU - this will only cause the GUI to become unresponsive."

If you do not use GUIGetMsg, e.g. in an OnEvent idle loop, you do need a Sleep(10) in there. :bye:

M23
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users