标题:asp 延 时 总 结
只看楼主
ysf0181
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:55
帖 子:914
专家分:2385
注 册:2006-10-4
结帖率:76.71%
 问题点数:0 回复次数:4 
asp 延 时 总 结
asp有个特点,就是一个页面(无传递值(get不一样,form可以一样))执行中,如果还有人再次打开该页面,处理程序会放到等待上次用户执行该页面完成才能继续执行。也就是多线程下,页面被打开用户数同时个数,只能是同时一个人。所以,要达到知道用户退出,服务器来发,必须不同页面(同一个页面需要传送参数也算不同页面),不然会卡住。
<%@ Language="VBScript" codepage ="936" EnableSessionState=false %>  头部加了这个是突破线程的限制,那么应用程序池 web园 ,线程 为 1 也可以达到延时的效果。

 asp无传递值时,打开同一个页面,这个页面必须等待上次用户打开页面加载完成了,才处理第二个人打开页面。
 asp有传递值不一样(post可以一样),就不会等待。

ceshi.asp的代码:

<%@ Language="VBScript" codepage ="936" EnableSessionState=false %>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<%

'response.Cookies("aa") = 111
'Application.Lock()
'Application("aa") = "aa"
'Application.UnLock()
Set ASP2DLL = Server.CreateObject("ASP2DLL.Demo")


'set conn = ASP2DLL. sql2005("26E6A42653BC462\SQL2005", "test","test","test")
'set rs = ASP2DLL.rs()
'rs.open"select * from mingzi order by id desc",conn,1,1
'do while not rs.eof
'   response.write rs("mingzi")&"<br>"

''rs.movenext
'loop
'rs.close
'set conn2 = ASP2DLL.sql2000sp4(fuwuqi, zhanghao, mima, data) '测试可以用

'ASP2DLL.hello(12)
ASP2DLL.IsClientConnectedPandu("aa")
Set ASP2DLL = Nothing



asp2dll---aspmod 代码:
 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")
   ' If Application("IsClientConnectedPandu") = "" Then
     '  Application("IsClientConnectedPandu") = 1  'Response.Redirect ("?")
     '  Response.Write "<script>alert('程序初始化,可正常使用了');location.href='?'</script>"
       'Server.Transfer ("?")
     '  Response.End
   'End If '该过程是为第一次编译,第一次编译会卡住 IIS 访问进程
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


Private Sub Class_Initialize()
ASP2DLL_Initialize
End Sub

Private Sub Class_Terminate()
ASP2DLL_Terminate
End Sub



asp2dll---demo 代码:
Public Sub hello(val)
Response.Write ("Hello World!")
Dim i
    For i = 0 To val
       ' Server.ScriptTimeout = 10
        If Application("ceshi") = 1 Then
           Exit For
        End If
        Response.Write i & "<br>"
        Response.Flush
        
        Delay (1)
    Next

End Sub
Public Sub hello2(val)
Response.Write ("Hello World!")
Dim i
    For i = 0 To val
       ' Server.ScriptTimeout = 10
        If Application("ceshi") = 1 Then
           Exit For
        End If
        Response.Write i & "<br>"
        Response.Flush
        
        Call Sleep(1000)
    Next

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 Function sql2000sp4(fuwuqi, zhanghao, mima, data)
   Dim conn
   Set sql2000sp4 = Server.CreateObject("ADODB.CONNECTION")
   'conn = "provider = sqloledb ; data source = (" & fuwuqi & ") ; uid = " & zhanghao & " ; pwd = " & mima & "; database = " & data
'错误 conn = "provider=sqloledb ;data source = (local) ;uid=" & zhanghao & " ;pwd=" & mima & ";database=" & data & ""
   conn = "provider=sqloledb;data source=" & fuwuqi & ";uid=" & zhanghao & " ;pwd=" & mima & ";database=" & data & ""
   '空格会引起连接数据库失败 错误写法: uid = " & zhanghao & " 正确写法:uid=" & zhanghao & "
   sql2000sp4.open conn
End Function
Public Function sql2005(fuwuqi, zhanghao, mima, data)
   Dim conn
   Set sql2005 = Server.CreateObject("ADODB.CONNECTION")
   'conn = "provider = sqloledb ; data source = (" & fuwuqi & ") ; uid = " & zhanghao & " ; pwd = " & mima & "; database = " & data
'错误 conn = "provider=sqloledb ;data source = (local) ;uid=" & zhanghao & " ;pwd=" & mima & ";database=" & data & ""
   conn = "provider=sqloledb;data source=" & fuwuqi & ";uid=" & zhanghao & " ;pwd=" & mima & ";database=" & data & ""
   '空格会引起连接数据库失败 错误写法: uid = " & zhanghao & " 正确写法:uid=" & zhanghao & "
   sql2005.open conn
End Function
Public Function access(lujing)
   Dim conn
   Set access = Server.CreateObject("ADODB.CONNECTION")
   conn = "provider=microsoft.jet.oledb.4.0;data source=" & lujing
   access.open conn
End Function

Public Function rs()
  Set rs = Server.CreateObject("adodb.recordset")
End Function


Public Function IsClientConnectedPandu(id_)
   
  '控制打开的页面个数 开始
   'If Application("dizeng" & id_) > 0 Then
  '    Response.Write "<script>alert('您打开的页面太多了,该页面只能打开一个');</script>"
   '   Exit Function
  ' End If
  '控制打开的页面个数 结束了
   
   
   Dim ii
   ii = 0
   Do While Response.IsClientConnected
'================================
'在这里修改或自定义要执行的ASP代码
   
     ii = ii + 1
     Response.Write ii & "--"
     'Response.Write Application("dizeng") & "我晕..." & Application("dizeng" & id_)
     
     'Application("dizeng" & id_) = Application("dizeng" & id_) + 1
     
    ' youdezhi = Application("dizeng" & id_)
'================================
     Response.Flush
      '
    'Delay (1) '
     Call Sleep(1000)
    ' Response.Clear
     If Response.IsClientConnected = False Then
        'Application("dizeng" & id_) = 0
        'Response.Cookies("ceshi") = 1
     End If
   Loop
  
End Function

[ 本帖最后由 ysf0181 于 2014-3-3 15:18 编辑 ]
搜索更多相关主题的帖子: 应用程序 服务器 多线程 用户数 false 
2014-03-02 11:12
wp231957
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:神界
等 级:版主
威 望:422
帖 子:13681
专家分:53296
注 册:2012-10-18
得分:0 
貌似挺厉害   可惜asp不懂

DO IT YOURSELF !
2014-03-02 15:56
hu9jj
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:红土地
等 级:贵宾
威 望:396
帖 子:11713
专家分:43267
注 册:2006-5-13
得分:0 
学习

活到老,学到老! http://www. E-mail:hu-jj@
2014-03-04 20:46
kwt3000
Rank: 2
等 级:论坛游民
威 望:1
帖 子:12
专家分:20
注 册:2014-4-19
得分:0 
学习
2014-04-19 10:57
鸥翔鱼游
Rank: 5Rank: 5
等 级:职业侠客
帖 子:182
专家分:323
注 册:2014-4-19
得分:0 
楼主发帖辛苦了  赞一个
2014-04-21 13:15



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-427884-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.049171 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved