asp调用vb插件形成延时不使CPU 100%,使用cpu为 零
vb代码:Private Sub Class_Initialize()
ASP2DLL_Initialize
End Sub
Private Sub Class_Terminate()
ASP2DLL_Terminate
End Sub
Public Sub hello()
Response.Write ("Hello World!")
End Sub
Public Function Delay(DT As Single)
'延时 DT 秒
'当 DT=0,返回Delay状态: True:未完成, False:已完成
Dim t1 As Single
Static InDelay As Boolean
'
If InDelay Or DT <= 0 Then
Delay = InDelay
Exit Function
End If
'
InDelay = True
t1 = Timer
Do Until Timer - t1 > DT
Call Sleep(10)
DoEvents
Loop
InDelay = False
Delay = False
End Function
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public objContext As ObjectContext
Public Application As ASPTypeLibrary.Application
Public Server As ASPTypeLibrary.Server
Public Session As ASPTypeLibrary.Session
Public Response As ASPTypeLibrary.Response
Public Request As ASPTypeLibrary.Request
Public Sub ASP2DLL_Initialize()
On Error Resume Next
Set objContext = GetObjectContext
Set Application = objContext.Item("Application")
Set Server = objContext.Item("Server")
Set Session = objContext.Item("Session")
Set Request = objContext.Item("Request")
Set Response = objContext.Item("Response")
End Sub
Public Sub ASP2DLL_Terminate()
On Error Resume Next
Set Application = Nothing
Set Server = Nothing
Set Session = Nothing
Set Request = Nothing
Set Response = Nothing
Set objContext = Nothing
' Set Sleep = Nothing
End Sub
asp代码:
dim t1,t2,lsabc,thetime
t1=timer
'response.write t1&"<br>"
Dim ASP2DLL
Set ASP2DLL = Server.CreateObject("ASP2DLL.Demo")
ASP2DLL.hello()
ASP2DLL.Delay(0.5) '
Set ASP2DLL = Nothing
t2=timer
thetime=cstr(int(((t2-t1)*10000 )+0.5)/10) '?
response.write "<br>"&thetime&"<br>"
附件在我的QQ群共享里有。
[ 本帖最后由 ysf0181 于 2013-12-26 12:42 编辑 ]