Jump to content

Time delay on autoupdate check


storme
 Share

Recommended Posts

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

Link to comment
Share on other sites

So it would appear as if this is the best way of implementing a delayed self-updater.

Thanks for the feedback

Link to comment
Share on other sites

  • 2 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...