Timing in the ASP in order to complete certain functions, we need to delay the output, so that the script to run a longer time, such as chat room program, we know that there are two ways to update the content of the dialogue, one is
Client automatically refresh, every once in a while to the server query to see if there is no new content, and the other is the server to actively output new content, the two
The advantages and disadvantages of the method is obvious, the former content is not real-time, but the burden on the server is lighter, the latter, due to the need for a long time on the server to execute the foot
Ben, so the number of times, of course, is a tired server work.
For the latter application, we need to delay the implementation of the ASP, but not empty the server resources, such as adding an infinite loop, so that soon
Eat your CPU, only in the loop as a timer function, so that each cycle can hang must be time, then this time the CPU is idle, so
To not let the CPU "become" the Machine
Let's take a look at this example http://chat.aaaaa.com.cn/question/disptest.asp, and see if it's like a chat room that's not like the blue sea and the silver sand.
Expression
There is no settimeout this kind of timing statement in ASP, we need to use ASP component to solve, similarly, can use VB6 to compile, concrete operation method Reference
In order to suspend the thread, we need to use the WIN32API function sleep, the same new active DLL project, named Timer,
Class name is sleep.
Sleep This win32api function can be found in VB6 's own API text browser with its declarative method
Now the class Sleep program is as follows, this component program is very simple, I do not explain more.
Private Declare Sub sleep Lib "kernel32" (ByVal dwmilliseconds as Long)
Private M_set as Long
Public Property Get Setup () as Long
Setup = M_set
End Property
Public Property Let Setup (Strset as Long)
M_set = Strset
End Property
Public Function Sleeptime ()
Sleep (Setup)
End Function
Compile it to generate Timer.dll This component DLL, if you do not write VB program, then you can also find in the downloaded package Timer.dll
This file. Copy it to the Windows directory and enter it in MS-DOS mode
C:\windows\regsvr32 Timer.dll
Complete the component registration, you can also use this timing component.
Now explain the ASP call file just by the first. See how this component uses
* Application of Timer
<title> Timer Application </title>
<body>
<%
' This is the script execution time, default is 90 seconds, need to change a bit, otherwise in 90 seconds the program will be interrupted ' 3600 is an hour
server.scripttimeout=3600
Set Obj=server.createobject ("Timer.sleep")
' Parameter 1000 hangs for the thread for a second and can be set randomly
obj.setup=1000
Do While True
Response.Write "(" &right (time,8) & ") Hello, the count is now <font color=red>" &application "(" Time_count ")
& "</font><br>"
Obj.sleeptime
Application ("Time_count") =application ("Time_count") +1
If not response.isclientconnected Then
Set obj=nothing
Session.Abandon
End If
Loop
%>
</body>
Well, I'm going to pack up the code, and let's see what this component can do for you, it might be useful, but it could be helpful,
The operating environment for the above components is: PWIN98+PWS4
Nt40+iis40