DigDeep Posted September 2, 2015 Share Posted September 2, 2015 (edited) Hi,I have a too big code which runs in Process 24/7 looking for any issues with multiple applications on the machine. If any application is not running or found bad, it tries to get them fixed. My issue is that I want my code to PAUSE if Internet connection is not there and as soon as the internet connection comes back it should RESUME.While _WinAPI_IsInternetConnected() Looks for issues... Looks for issues... Looks for issues... Looks for issues... Looks for issues... Continueloop WendI am able to do my work by keeping the _WinAPI_IsInternetConnected() just before "Looks for issues" but then I have to keep adding this before every Function...If I want to keep it as above, then the code exits if no Internet connection found. Is there any way I can keep this to at the starting so it will keep checking for an Active Internet connection all the time and until found it will pause the code Or not take any actions inside While.Also, I am not showing the icon in System Tray, so I think using Pause function via TrayItemSetState might not work.Thanks in advance. Edited September 2, 2015 by DigDeep Link to comment Share on other sites More sharing options...
Jfish Posted September 3, 2015 Share Posted September 3, 2015 (edited) Removed mine - as it would not have worked. Edited September 3, 2015 by Jfish Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
Surya Posted September 3, 2015 Share Posted September 3, 2015 Try this (Code not tested):#include <WinAPIDiag.au3> AdlibRegister("checkconnection",250) ;Your code here ,,,,,,,,,,, ;.,,,,,,,,,,,,,,,, func checkconnection() Do sleep(50) until _WinAPI_IsInternetConnected() endfuncI dont know wether that works anyway test it No matter whatever the challenge maybe control on the outcome its on you its always have been. MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition) Link to comment Share on other sites More sharing options...
jguinch Posted September 3, 2015 Share Posted September 3, 2015 Another way :While 1 If _WinAPI_IsInternetConnected() Then Looks for issues... Looks for issues... Looks for issues... Looks for issues... Looks for issues... Else Sleep(1000) EndIf WEnd Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Surya Posted September 3, 2015 Share Posted September 3, 2015 jguinch but in your code while looking for the issues if the internet connection looses the loop will still continue it wont poll every second No matter whatever the challenge maybe control on the outcome its on you its always have been. MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition) Link to comment Share on other sites More sharing options...
jguinch Posted September 3, 2015 Share Posted September 3, 2015 You said I want my code to PAUSE if Internet connection is not there and as soon as the internet connection comes back it should RESUM.So how can you detect if the connection comes back ? Not with a blocking function, sure.With my code, if the internet connection is down, the loop continues and check it after 1 second. If it is OK, the issues check performs. Else, waits for 1 second and re-check... Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Surya Posted September 3, 2015 Share Posted September 3, 2015 (edited) Another way :While 1 If _WinAPI_IsInternetConnected() Then Looks for issues... Looks for issues... Looks for issues... Looks for issues... Looks for issues... Else Sleep(1000) EndIf WEnd in that code if the internet is connected then the If command will satisfy and pass on to the "look for issues" but while on the "look for issues" if the internet is lost the program will still continue with "look for issues" without internet i will demonstrate with an example:While 1 If _WinAPI_IsInternetConnected() Then ;when connection is there if satisfies sleep(5000) ConsoleWrite("Connection still exists") ;here even if the connection is terminated the script continues Else Sleep(1000) EndIf WEndbut if you use adlibregister it will poll for internet connection.the function registered via adlibregister wont block the script unless not connected to the internet if you want to have a larger poll interval you could use a larger function call interval in adlibregister Edited September 3, 2015 by Surya No matter whatever the challenge maybe control on the outcome its on you its always have been. MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition) Link to comment Share on other sites More sharing options...
DigDeep Posted September 3, 2015 Author Share Posted September 3, 2015 (edited) @jguinchWell, this works. But the issue found that if internet gets disconnected while fixing the issue the code still continues (which is good) but when the Internet connection is back, the code does not resume.Say, the issue found was at the 2nd Looks for issues. I found that if Internet is disconnected, and resumed the code does not restart. It still runs at the Process, but does not do anything... What I want is, if Internet gets disconnected also in between if any actions are being done and then Internet is back, the code should restart from While 1 again, identify the issue and restart the fix.While 1 If _WinAPI_IsInternetConnected() Then Looks for issues... Looks for issues... Edited September 3, 2015 by DigDeep Link to comment Share on other sites More sharing options...
jguinch Posted September 3, 2015 Share Posted September 3, 2015 Ok, I understand.Something like this should be simplerWhile 1 Sleep(1000) If NOT _WinAPI_IsInternetConnected() Then ContinueLoop Process First issues check If NOT _WinAPI_IsInternetConnected() Then ContinueLoop Process Second issues check If NOT _WinAPI_IsInternetConnected() Then ContinueLoop Process Third issues check ; End ExitLoop WEnd Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
DigDeep Posted September 3, 2015 Author Share Posted September 3, 2015 (edited) @jguinchBoth of your codes works fine. But one of the issue mentioned above still persists.While fixing is in process, if Internet turns OFF and fixing stops, then the file shows as running in Process, but it just sits like that. It no longer checks for issues in loop. I have to either exit the Process and restart it or restart the machine which I don't want.1. If No Internet connection then continue loop to wait for connection.2. If Active Internet connection then run the functions.3. If Internet is interrupted then it should go back to loop state.4., When Internet is back ON, it should start running functions.Also I have removed the ExitLoop as it was killing the process if no issues were found. Edited September 3, 2015 by DigDeep Link to comment Share on other sites More sharing options...
jguinch Posted September 3, 2015 Share Posted September 3, 2015 So can you post a real code, not only Looks for issues... ? It's not easy to answer without knowing do how you process... Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
DigDeep Posted September 3, 2015 Author Share Posted September 3, 2015 @jguinchSure. Let me work on this a bit. If not able to figure out will post few lines.Thanks for help. 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