storme Posted November 7, 2011 Share Posted November 7, 2011 G'day All I'm writing a simple tray program so my customers can run some simple checks, send me screen shots, etc Of course over time I want to add to it and it needs to auto update. I've worked out the following requirements 1. Wait for a "period of time" to check for updates after starting (So that the computer isn't burdened with downloading the update as it starts. 2. If there is no update then wait a longer period (1 day) before checking again. (I don't want it checking all the time but I do want it to keep checking on those systems that are always on) 3. If there is no internet connection then keep checking every 2 minutes untill and internet connection is made (this is good for wireless broadband connections that arn't always on.) 4. The update shouldn't run if there is code running that can't be interrupted. 5. Very low CPU usage when not active So the skeleton of code I've come up with is this. Let me know what you think and if there is a different/better way. Global $bDisableUpdate = False ; Set to true to stop autoupdate (NB for critial code) SetupAutoUpdate(60) ; Delay update by 60 seconds ;all the tray code ;a while loop to keep the program running ;other funcs, etc Func SetupAutoUpdate($iDelayTime = 0) AdlibRegister(CheckUpdate, $iDelayTime * 1000) ; set wait time for first check EndFunc ;==>SetupAutoUpdate Func CheckUpdate() Static $iUpdateInterval = 120000 ; Wait 2 minutes for next check If Not $bDisableUpdate Then If InternetConnected() Then DoUpdate() ; This line will only execute if there was no updata ; No update needed so delay next update check by 1 day $iUpdateInterval = 86400000 ; 1000ms*60s*60m*24h = 1 day EndIf EndIf AdlibRegister(CheckUpdate, $iUpdateInterval) ; set wait for next check EndFunc ;==>CheckUpdate Func InternetConnected() ; return True if conneciton available Return True EndFunc ;==>InternetConnected Func DoUpdate() ; return False if no update needed ; If update is done then function will exist this script EndFunc ;==>DoUpdate Thanks for any assistance John Morrison Some of my small contributions to AutoIt Browse for Folder Dialog - Automation SysTreeView32 | FileHippo Download and/or retrieve program information | Get installedpath from uninstall key in registry | RoboCopy function John Morrison aka Storm-E Link to comment Share on other sites More sharing options...
storme Posted November 9, 2011 Author Share Posted November 9, 2011 So it would appear as if this is the best way of implementing a delayed self-updater. Thanks for the feedback Some of my small contributions to AutoIt Browse for Folder Dialog - Automation SysTreeView32 | FileHippo Download and/or retrieve program information | Get installedpath from uninstall key in registry | RoboCopy function John Morrison aka Storm-E Link to comment Share on other sites More sharing options...
briandoc Posted January 10, 2012 Share Posted January 10, 2012 Thanks for the code shell. Looking to do this for a small script I have and didn't want to get ultra-complicated. Will use your layout today and see if I can get it working and if I can suggest any tweaks. Thanks for submitting. 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