Jump to content

jp123

Members
  • Posts

    10
  • Joined

  • Last visited

jp123's Achievements

Seeker

Seeker (1/7)

0

Reputation

  1. I modified the sample code from the "Interrupting a running function" Wiki, and as soon as Ping is called, the GUI freezes for 15 seconds when the network cable is unplugged. The loop that starts after Ping is called doesn't begin until ping returns something, so the loop only runs once (because ping returns 0 when the cable is unplugged). #include <GUIConstantsEx.au3> ;Declare a flag Global $fRunOne = False Global $pingtest = 1234567890 ;just giving it a value here to see when it changes - a ping return will hopefully never be 1,234,567,890 milliseconds (two weeks!) Opt("GUIOnEventMode", 1) $hGUI = GUICreate("Test", 500, 500) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $hButton_1 = GUICtrlCreateButton("Func One", 10, 10, 80, 30) GUICtrlSetOnEvent($hButton_1, "_Func_1") $hButton_2 = GUICtrlCreateButton("Func Two", 10, 50, 80, 30) GUICtrlSetOnEvent($hButton_2, "_Func_2") GUISetState() While 1 Sleep(10) ;Check if the flag has been set by the OnEvent function If $fRunOne Then ;Now start the "real" function from within the main code _Func_1_Run() EndIf WEnd Func _Func_1() ; Set the flag within the OnEvent function Global $fRunOne = True EndFunc ;==>_Func_1 Func _Func_1_Run() ConsoleWrite(@CRLF & "$pingtest value before ping = " & $pingtest & @CRLF) $pingtest = Ping("www.google.com",3000) For $i = 1 To 6 ;loop runs every .5 seconds, need 3-second limit If $fRunOne Then ConsoleWrite("Func_1_Run is running, loop " & $i & @CRLF) ConsoleWrite("$pingtest valuefor loop " & $i & " = " & $pingtest & @CRLF) If $pingtest <> 1234597890 Then ConsoleWrite("exiting loop" & @CRLF) ExitLoop EndIf Sleep(500) EndIf Next ConsoleWrite(">Func 1 Ended" & @CRLF) Global $fRunOne = False EndFunc ;==>_Func_1_Run Func _Func_2() ;~ For $i = 1 To 3 Global $fRunOne = False ConsoleWrite("+Func 2 Running, ending _Func_1_Run" & @CRLF) ;~ Sleep(100) ;~ Next ConsoleWrite(">Func 2 Ended" & @CRLF) EndFunc ;==>_Func_2 Func _Exit() Exit EndFunc ;==>_Exit
  2. Thanks for the suggestion - some of the clients running this script may be connected to a LAN but not the internet, so the network adapter status might be OK. I tried _WinAPI_IsInternetConnected with WinAPIEx_3.7_3380, and even with the network cable unplugged is reported back that everything was OK, not sure why. And to top it all off, many of the clients will be running XP, even some still on Windows 2000, so even if _WinAPI_IsInternetConnected worked I couldn't use it (says it requires Vista or later).
  3. @czardas: I started the other ping timeout thread in hopes that there was another "undocumented" way to work with Ping that would point me in the right direction - like there is with Sleep (the answer that started this whole extended conversation). It's a related issue, but not the same question, and if I can firgure out the ping problem everything else is a non-issue. I realize that connection to a router is not the same as connection to the internet, but in my case it seems that the router isn't part of the issue becuase when I test with "no internet connection", I'm physically unplugging the cable from my computer. I need the responsiveness of the GUI to be the same regardless of OS or network condition. "The timeout will occur after waiting for the return ping if it dosn't arrive within the alloted time." - The alloted time is what I'm trying to control. No matter what I specify for the ping timeout, it takes my machine 15 seconds for ping to return 0, and we're getting into the topic of the other thread, so I'm just commenting on your comment here Three seconds is a specification from the client. They don't want the user to have to wait for more than three seconds to interact with the GUI. I'm not at my dev machine right now, will post some code later - in a new thread.
  4. I've tried this from several different angles using examples from other posts & suggestions above, still no luck. What I really need to accomplish is to reliably determine whether or not the client running the script has an active internet connection, within 3 seconds of when the script runs. Ping function takes 15 seconds to timeout, no matter what I set the timeout to. A DllCall to wininet.dll does not report the correct information - it says my internet connection is active even when the network cable is unplugged. Both InetGet() and _INetGetSource() take just as long as Ping does to come back with nothing. Trying to use a While loop containing Sleep to test a variable at a certain interval based on any of the above hasn't worked because the loop doesn't start until the methods above return their condition, which always takes more than the desired 3 seconds when there's no internet connection. @AdmiralAlkex - background downloading apparently doesn't work in this situation because it appears that the download has to start before it can "move" to the background and let something else happen. I'm probably wrong about the specifics, but I'm not wrong that it doesn't work when my network cable is unplugged. @czardas - Interrupting a running function doesn't work because when I put Ping (or anything else) into a function to try to interrupt it, it just freezes that function until timeout. After everything I've seen AutoIt do so simply & efficiently, it just seems like there should be some way to get this off the ground. Test internet connection state in 3 seconds max.
  5. OK, but there are no handshakes going on at all when my network cable is unplugged...?
  6. Anyone aware of a reason that the following code would take 15 seconds (rather than two seconds) to display the MsgBox when I unplug my network cable? Also, @error is 0 even though ping failed. Hmmm... $PingTime = Ping("www.google.com",2000) MsgBox(0, "", "$PingTime = " & $PingTime) MsgBox(0, "", "@error = " & @error) This thread ended with basically the same question a while back:
  7. Seems I don't quote understand how this works - I didn't intend to "make" the GUI unresponsive, I was under the impression that AutoIT had to wait for the image to download (or timeout trying) before moving on to the next step. The way it is now, if there were a "Cancel" button, the user couldn't click it until the image were done downloading (or timed out trying)... I thought AutoIt had to do one thing at a time - are you saying I can have it try to download the image and allow user interaction simultaneously?
  8. All makes sense now. I don't actually need the 1ms sleep, 100ms should work. I'm looking for the results from "$PingTime = Ping("www.google.com",5000)" in order to spend a limited amount of time determining if there's an internet connection when the script first runs. Checking that every tenth of a second seems reasonable. The script downloads a few images from the web - the GUI is unresponsive until it's done downloading (or times out), and I don't want the user to think the program is frozen if they don't have an internet connection, so I have to check that first an not try to download any images if it's not even possible. Thanks for the tip!
  9. Documentation says the sleep function delay value is in milliseconds, but in this case it appears to be more like centiseconds. This code displays the message box after a little more than 5 seconds, instead of .5 seconds. When I change 500 to 700, it takes a little over 7 seconds. $Count = 0 While $Count < 500 $Count += 1 Sleep(1) WEnd MsgBox(0, "", $Count & " loops") What am I missing?
×
×
  • Create New...