Execute a Sub every hour

Hello Experts,

I need to execute a sub routine every hour, and I have the following code to so, but it's not happening...

	If (Session("getRates") = "") Or (CDate(Session("getRatesTime")) > Now()) Then
		
		'Call UpdateRates
		
		Session("getRates") = False
	
		'Renew Rates every hour
		Session("getRatesTime") = DateAdd("s", 3, Now())	'DateAdd Intervals: s=secs; n=minutes; h=hrs

	End If

Response.Write("ts = " & Session("getRatesTime") & "<br>")
Response.Write("now = " & Now())

Open in new window


It executes once, whern getRates = "", then the first Writeline doesnt change.

Any ideas?

I have it set to 3s for this test...

Thank you.
APD TorontoAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Robert SchuttConnect With a Mentor Software EngineerCommented:
Try switching it around, also you don't need CDate:
	If (Session("getRates") = "") Or (Session("getRatesTime") < Now()) Then

Open in new window

0
 
Robberbaron (robr)Commented:
while previos comment is probably the correct test, what method did you have in mind for getting the script to wait the 3600 seconds.
What causes the script to reload ?  Page.Redirect ?

your asp page is going to be running continuously.... is that what you expect ?

executing every hour, i think it would be more efficient to have the script run using windows scheduler and update a background file with the data but that may not suit your users .
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I do agree 100% that this should not be  run as asp page, but by a scheduler
0
 
Robert SchuttSoftware EngineerCommented:
I assumed it would not be running continuously but rather check on each use of a page (or even any page on a site via a global include file) whether a set of information needed refreshing.

EDIT: For that of course you may need to use Application instead of Session. But if you just need this within each individual user's session then it should do the job.
0
All Courses

From novice to tech pro — start learning today.