In the ASP, we need to delay the output in order to complete certain functions, let the script run for a longer time, for example, chat room program, we know that there are two ways to update the conversation, 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:windowsegsvr32 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>
<%
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.