ASP server side sleep or delay response

在server side的ASP程式,怎麼做出sleep, 或暫停一小段時間的效果?

這個不錯。利用dos下的timeout指令來做delay response效果。timeout指令理應耗的CPU resource很少,所以真的就有sleep的效果。

function Sleep(seconds)
	set oShell = CreateObject("Wscript.Shell")
	cmd = "%COMSPEC% /c timeout " & seconds & " /nobreak"
	oShell.Run cmd,0,1
End function

Sleep(5)

這招看來也不錯。

function sleep(seconds)
   set shell = CreateObject("WScript.Shell")
   if seconds>=1 then shell.popup "pausing",seconds,"pause",64
end function

Sub DelayResponse(numberOfseconds)
	Dim WshShell
	Set WshShell=Server.CreateObject("WScript.Shell")
	WshShell.Run "waitfor /T " & numberOfSecond & "SignalThatWontHappen", , True
End Sub

這個也可以。利用dos下的ping指令來做delay response效果,但ping的執行就會耗些server CPU resource:

function sleep(scs)
    Dim lo_wsh, ls_cmd
    Set lo_wsh = CreateObject( "WScript.Shell" )
    ls_cmd = "%COMSPEC% /c ping -n " & 1 + scs & " 127.0.0.1>nul"
    lo_wsh.Run ls_cmd, 0, True 
End Function

sleep(5)

這個也可以達到delay response效果,但事實上成試試再拼命跑迴圈、耗CPU資源、並沒有sleep,所以不建議使用。

Sub MyDelay(NumberOfSeconds)
	Dim DateTimeResume
	DateTimeResume= DateAdd("s", NumberOfSeconds, Now())
	Do Until (Now() > DateTimeResume)
	Loop
End Sub

註:以上程式碼是從stackoverflow參考而來,並沒有每個都實際測試過。