danb Posted September 24, 2013 Share Posted September 24, 2013 I have nice lag in next script. If i comment InetrRead and use Sleep GUI is working as expected. It seems to be an incompatibility betwen GUICtrlSetData and InetRead. Please give me an solution. Thanks. expandcollapse popup#include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> Func Example() Local $widthCell, $msg, $iOldOpt, $sMsg, $hButt01 $sMsg = "" GUICreate("My GUI", 400, 830) $hEdit01 = GUICtrlCreateEdit("", 2, 2, 400, 800, $ES_READONLY + $WS_VSCROLL + $WS_HSCROLL) $hButt01 = GUICtrlCreateButton("Button Test aaaaaaa E&xit", 100, 804) GUICtrlSetState($hEdit01, $GUI_FOCUS) GUISetState() GUICtrlSetData($hEdit01, $sMsg) $sMsg = "" $sIP = "10.40.2.61" ; this IP should be off line For $ii = 1 To 100 Step 1 $sMsg &= @CRLF & $ii GUICtrlSetData($hEdit01, $sMsg) $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop ElseIf $msg = $hButt01 Then ExitLoop EndIf ; Sleep (4000) $sData = InetRead("http://" & $sIP & "/prdsc.htm") Next $sMsg &= @CRLF & "Press Buton again to exit." GUICtrlSetData($hEdit01, $sMsg) ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop ElseIf $msg = $hButt01 Then ExitLoop EndIf sleep(100) WEnd EndFunc ;==>Example Link to comment Share on other sites More sharing options...
kylomas Posted September 24, 2013 Share Posted September 24, 2013 danb, First, you are not running the function. Post code that shows the problem. Secondly, do you really want to read the IP you're pointing to 100 times? Finally, what makes you think that guictrlsetdata has anything to do with inetread? kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
danb Posted September 24, 2013 Author Share Posted September 24, 2013 (edited) thanks for fast replay. First, you are not running the function. I only posted part to show problem. It seems i cut to much, and dont yet figured how to update first post so here is code expandcollapse popup#include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> Example() Func Example() Local $widthCell, $msg, $iOldOpt, $sMsg, $hButt01 $sMsg = "" GUICreate("My GUI", 400, 830) $hEdit01 = GUICtrlCreateEdit("", 2, 2, 400, 800, $ES_READONLY + $WS_VSCROLL + $WS_HSCROLL) $hButt01 = GUICtrlCreateButton("Button Test aaaaaaa E&xit", 100, 804) GUICtrlSetState($hEdit01, $GUI_FOCUS) GUISetState() GUICtrlSetData($hEdit01, $sMsg) $sMsg = "" $sIP = "10.40.2.61" ; this IP should be off line For $ii = 1 To 100 Step 1 $sMsg &= @CRLF & $ii GUICtrlSetData($hEdit01, $sMsg) $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop ElseIf $msg = $hButt01 Then ExitLoop EndIf ; Sleep (4000) $sData = InetRead("http://" & $sIP & "/prdsc.htm") Next $sMsg &= @CRLF & "Press Buton again to exit." GUICtrlSetData($hEdit01, $sMsg) ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop ElseIf $msg = $hButt01 Then ExitLoop EndIf sleep(100) WEnd EndFunc ;==>Example Secondly, do you really want to read the IP you're pointing to 100 times? No, i read 300 differnt IP's, from which some are offline. I need to read some information and check some data. In example i read 1 offline IP, just to make problem easy to identify. If 100 is to much, change it to lower value. I just used an old example to reproduce problem. Finally, what makes you think that guictrlsetdata has anything to do with inetread? If you replace inetread with sleep GUI lag is gone away. EDIT: To see the problem you have to switch to another application and back. Edited September 24, 2013 by danb Link to comment Share on other sites More sharing options...
MHz Posted September 24, 2013 Share Posted September 24, 2013 The lag is InetRead is not returning until completion of the call. In other words, it is a blocking function as your script will pause until the function ends. Being in the message loop of the Gui makes the window unresponsive until InetRead completes. You could try using Ping 1st (which has a timeout) and if successful, then use InetRead. You will still endure some time of blocking flow of the script. Or perhaps try doing the InetRead in a separate process. Link to comment Share on other sites More sharing options...
danb Posted September 26, 2013 Author Share Posted September 26, 2013 I solved my current problem(see it in next post), but first thing first ... 1) First thought Why there are no support for threads ? Answer myself : Well there will be an hell. 2) Second thought Right, but you can offer 2 threads, 1 for GUI, 1 for main thread. Answer: this will not work because you can not predict the way the AutoIt users write their code. Simple code example Func main() ... a=1 GUICtrlSetOnEvent(-1, "_ButtonA") ... if a=1 then a=2 ; a is ? ... EndFunc Func _ButtonA() ... if a=1 then a=0 ; a is ? ... EndFunc And at line '; a is ?' , a may be 0, 1, or 2. This is multithreading. 3) Third thought So the script should be unithread. And this implies laggy interfaces. Second proccess is not an solution. Proccess with GUI will still need to wait for data from se working proccess, lyke InetRead wait for page. It also needs inter-proccess comunication which will complicate the solution unnecesary. In conclusion, for some application will be very nice to have multithread alternative. You may offer it without any support. But you may also need to offer at least PV semaphores, else it is useless. Link to comment Share on other sites More sharing options...
danb Posted September 26, 2013 Author Share Posted September 26, 2013 My solution is in this speciffic situation, to use an wrapper for InetRead. See InetRead2 function. expandcollapse popup#include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> Global $sMsg, $hEdit01 Example() Exit Func Example() Local $widthCell, $msg, $iOldOpt, $hWin, $sMsg, $hButt01 $sMsg = "" $hWin = GUICreate(@ScriptName, 400, 830) $hEdit01 = GUICtrlCreateEdit("", 2, 2, 400, 800, $ES_READONLY + $WS_VSCROLL + $WS_HSCROLL) $hButt01 = GUICtrlCreateButton("Button Test aaaaaaa E&xit", 100, 804) GUICtrlSetState($hEdit01, $GUI_FOCUS) GUISetState() GUICtrlSetData($hEdit01, $sMsg) $sMsg = "" $sIP = "10.40.2.3" ; this IP should be off line For $ii = 1 To 10 Step 1 Do $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop 2 ElseIf $msg = $hButt01 Then ExitLoop 2 EndIf Until $msg = 0 $sMsg &= @CRLF & $ii GUICtrlSetData($hEdit01, $sMsg) ; Sleep (4000) $sData = InetRead2("http://" & $sIP & "/prdsc.htm") Next ; $sMsg &= @CRLF & "Press Buton again to exit." ; GUICtrlSetData($hEdit01, $sMsg) ; wait again for an GUI event ; While 1 ; $msg = GUIGetMsg() ; If $msg = $GUI_EVENT_CLOSE Then ; ExitLoop ; ElseIf $msg = $hButt01 Then ; ExitLoop ; EndIf ; Sleep(100) ; WEnd MsgBox(0, @ScriptName, "Exit") EndFunc ;==>Example Func InetRead2(Const $sUrl) Global $sMsg Local $hInet, $ii $hInet = InetGet($sUrl, "", 1, 1) DO Sleep(100) ; $sMsg &= @CRLF & "InetGetInfo=" & InetGetInfo($hInet, 2) ; GUICtrlSetData($hEdit01, $sMsg) ; ControlSend("", "", $hEdit01, "{END}") Until InetGetInfo($hInet, 2) $ii = InetGetInfo($hInet, 3) InetClose($hInet) If $ii Then Return InetRead($sUrl, 0) Else Return SetError(@error, @extended, "") EndIf EndFunc but i prefered next version expandcollapse popup#include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> Global $bRun AutoItSetOption("GUIOnEventMode", 1) $bRun = True Example() Exit Func Example() Global $bRun Local $widthCell, $msg, $iOldOpt, $hWin, $sMsg, $hButt01 $sMsg = "" $hWin = GUICreate(@ScriptName, 400, 830) GUISetOnEvent($GUI_EVENT_CLOSE, "_ButtonA", $hWin) $hEdit01 = GUICtrlCreateEdit("", 2, 2, 400, 800, $ES_READONLY + $WS_VSCROLL + $WS_HSCROLL) $hButt01 = GUICtrlCreateButton("Button Test aaaaaaa E&xit", 100, 804) GUICtrlSetOnEvent($hButt01, "_ButtonA") GUICtrlSetState($hEdit01, $GUI_FOCUS) GUISetState() GUICtrlSetData($hEdit01, $sMsg) $sMsg = "" $sIP = "10.40.2.3" ; this IP should be off line $ii = 1 While $bRun $sMsg &= @CRLF & $ii GUICtrlSetData($hEdit01, $sMsg) ; Sleep (4000) $sData = InetRead2("http://" & $sIP & "/prdsc.htm") $ii += 1 If $ii > 10 Then ExitLoop WEnd While $bRun Sleep(300) WEnd MsgBox(0, @ScriptName, "Exit") EndFunc ;==>Example Func _ButtonA() Global $bRun $bRun = False EndFunc Func InetRead2(Const $sUrl) Global $sMsg Local $hInet, $ii $hInet = InetGet($sUrl, "", 1, 1) DO Sleep(100) ; $sMsg &= @CRLF & "InetGetInfo=" & InetGetInfo($hInet, 2) ; GUICtrlSetData($hEdit01, $sMsg) ; ControlSend("", "", $hEdit01, "{END}") Until InetGetInfo($hInet, 2) $ii = InetGetInfo($hInet, 3) InetClose($hInet) If $ii Then Return InetRead($sUrl, 0) Else Return SetError(@error, @extended, "") EndIf EndFunc 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