Border = "0" marginwidth = "0" marginheight = "0" src = "/ ads / ad_txt_tom300.htm" frameborder = "no" width = "302" scrolling = "no" height = "148"> ------ ------------------------------------------------- --- In ASP, we are completed
When certain features, you need to delay output, so that the script runs longer, such as chat room programs, we know that there are two ways to update the dialogue, one is
The client automatically refreshes, queries the server every other period of time to see if there is no new content, and the other is that the server actively outputs new content, these two
The advantages and disadvantages of the way are obvious. The former content is not real-time, but the burden on the server is lighter, and then one, because it takes a long time to perform foot on the server.
Ben, therefore the number of people, of course, is a tired server.
For the latter application, we need to delay the execution of the ASP, but you can't use server resources. For example, add a infinite loop, so that this is soon
Eat your CPU, only in the loop like a timing function, let each loop can hang a time, then this time the CPU is idle, so
Not allowing CPU "When"
First look at this example http://chat.aaaa.com.cn/question/disptest.asp, look at the update visit to the chat room that is not like Bihai Yinshana
formula?
There is no timing statement such as settimeout in the ASP. We need to use ASP components to solve, and like, VB6 can be used, specific method reference
The approach of the previous component, in order to hang the thread, we need to use the Win32API function SLEEP, and create an Active DLL project, and the name is Timer.
Classified Sleep.
Sleep This Win32API function can find its declaration method in the API text browser comes with VB6
Now the program of Sleep is as follows, this component program is very simple, I don't have much to say.
Private Declare Sub Sleep Lib "Kernel32" (Byval dwmilliseconds as ring)
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 P>
To build it, generate Timer.dll's component DLL, if you don't write VB program, you can also find Timer.dll in the downloaded file package.
This file. Enter it in the MS-DOS mode in the MS-DOS mode to the Windows directory
C: / windows / regsvr32 timer.dll
Complete component registration, you can also use this timing component.
Now explain the ASP call file that just pressing the list. Take a look at how this component is used.
* Timer application
hEAD>
<%
'This is the execution time of the script, default is 90 seconds, you need to change a little, otherwise the program will be interrupted after 90 seconds after the 3600 is one hour.
Server.scripttimeout = 3600
Set obj = server.createObject ("timer.sleep")
'The parameter 1000 hangs a second for threads, you can set freely
Obj.setup = 1000
Do While True
Response.write "(" & Right (Time, 8) & ") Hello, now count the value of & applibility (" time_count ")
& " font>
"
Obj.sleeptime
Application ("time_count") = Application ("time_count") 1 p>
if NOT RESPONSE.ISCLIENTCONNECTED THEN
Set obj = Nothing
Session.Abandon
END IF P>
loop p>
%> p>
body>
html> p>
Ok, I pack the above code. Let's take a look at this component to help you, there may be no use, but it is also useful to use, p>
The operating environment of the above components is: PWIN98 PWS4 P>
NT40 IIS40