panlatv Posted December 17, 2007 Share Posted December 17, 2007 Hello,And sorry for my bad english.I don't want to stress the cpu, but i have a fonction to check all the time in a "GUI loop".So, what it's the better way to do this?Exemples with a GUI and a timer fonction, what it's the better way?- exemple 1:; >>> GUI GUICreate("exemple 1",200,200) $start=GUICtrlCreateButton ("Start", 5,5,42,24) $stop=GUICtrlCreateButton ("Stop", 5,55,42,24) GUISetState (@SW_SHOW) $time = TimerInit() ; >>> Loop While 1 if TimerDiff($time)>2000 then msgbox (0,"Time","It's time !!!",5) $msg = GUIGetMsg() Select case $msg = $start msgbox (0,"Start","hello") case $msg = $stop msgbox (0,"Stop","finish") case $msg = $GUI_EVENT_CLOSE exitloop EndSelect Wend Exit- exemple 2:; >>> GUI GUICreate("exemple 2",200,200) $start=GUICtrlCreateButton ("Start", 5,5,42,24) $stop=GUICtrlCreateButton ("Stop", 5,55,42,24) GUISetState (@SW_SHOW) $time = TimerInit() ; >>> Loop While 1 $msg = GUIGetMsg() Select case $msg = $start msgbox (0,"Start","hello") case $msg = $stop msgbox (0,"Stop","finish") case $msg = $GUI_EVENT_CLOSE exitloop case else if TimerDiff($time)>2000 then msgbox (0,"Time","It's time !!!",5) EndSelect Wend ExitOther way?Thank you Link to comment Share on other sites More sharing options...
Valuater Posted December 17, 2007 Share Posted December 17, 2007 Sleep(2000) ???? 8) Link to comment Share on other sites More sharing options...
panlatv Posted December 17, 2007 Author Share Posted December 17, 2007 (edited) Thank for your help Sleep(2000)????8)I don't think so, the help of autoit, say that a "sleep" in a "GUI loop" can stress the cpu or cause the GUI to become unresponsive .autoit help:Do not put a manual sleep in the loop for fear of stressing the CPU - this will only cause the GUI to become unresponsive.(and it's right) Edited December 17, 2007 by panlatv Link to comment Share on other sites More sharing options...
Valuater Posted December 17, 2007 Share Posted December 17, 2007 (edited) Read it againThe general layout of MessageLoop code is: While 1 $msg = GUIGetMsg() ... ... WEnd 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. The most important part "fortunately the GUIGetMsg function automatically idles the CPU when there are no events waiting."8) Edited December 17, 2007 by Valuater Link to comment Share on other sites More sharing options...
panlatv Posted December 17, 2007 Author Share Posted December 17, 2007 Read it againThe general layout of MessageLoop code is: While 1 $msg = GUIGetMsg() ... ... WEnd 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. The most important part "fortunately the GUIGetMsg function automatically idles the CPU when there are no events waiting."8)ok thank you, i understand now.But, my exemple can't use a sleep fonction, in reality, my program is a GUI for videolan player. You can record the television (DVB t), and my timer fonction check if it's time to recording something. So if i put a sleep fonction, i will lost some "recording start". Link to comment Share on other sites More sharing options...
Valuater Posted December 17, 2007 Share Posted December 17, 2007 Maybe take a look at AdlibEnable() 8) Link to comment Share on other sites More sharing options...
panlatv Posted December 17, 2007 Author Share Posted December 17, 2007 (edited) Maybe take a look atAdlibEnable()8)Woo!! perfect fonction, thanks a lot edit: How can i put "resolu" in the title of the topic? thank you Edited December 17, 2007 by panlatv 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