Link to home
Start Free TrialLog in
Avatar of dmaroff
dmaroff

asked on

Sleeping in ASP

Is there a way to pause or sleep during an ASP script.  Im writing a script in that I want the user to think that the computer is thinking, so I need some kind of sleep() function that will pause the script for about 10 seconds or so.

Thanks,
-Dan
Avatar of eladr
eladr

i think you can build a function
in javascript that do nothing and to set up setTimeout for this function.

elad
say

<% response.buffer=true%>
before <html> tag
and
when you need a sleep
call...
<%

myMinutes =2
Response.Flush
goSleep (myMinutes) %>

<%
function goSleep(myMinutes)
dim  koef, timekiller
     koef=60*100000
for i=0 to myMinutes*koef
  timekiller=timekiller+1
  timekiller=timekiller-1
next

end function
%>
<br>
finished sleeping.

where koef is some value you have to adjust depending on your
server CPU speed.
But, depending on now much your server is busy, you will get not exact amount time of sleep.
hope it helps

bagi
ASKER CERTIFIED SOLUTION
Avatar of ruperts
ruperts

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
And, another one:

<%
Sub Sleep(intMilliseconds)
    dteEnd = DateAdd("s", intMilliSeconds/1000, Now)
    Do While dteEnd > Now
        'Sleep
    Loop
End Sub

Call Sleep(5000)
Response.Write "Something"
%>
Avatar of dmaroff

ASKER

Good thinking it works great.  The only thing is that if I have a form that is posting to this page, it doesn't show this page until the page completely ends.  Any way around this?

Thanks,
-Dan
<% response.buffer=true%>
Pre wait code...

<% Response.Flush %>

waiting loop goes here!

<% Response.Flush %>
ruperts' code is an endless loop...
I've been too late.
Q: why is it endless??

A: It's not.

Except:
It is only endless if time stands still! But then if time stood still you wouldn't know that you where actually waiting for it to finish as time would not be passing!

(The above doesn't apply if time goes backwards - that's a whole new theory!)