ASP處理查詢逾時的解決函數

來源:互聯網
上載者:User
通常用於ASP查詢逾時,做出逾時提示,稍候重試的功能。主要應用了Response IsClientConnected這個關鍵代碼..

IsClientConnected 屬性唯讀,它指示自上次調用 Response.Write 之後,用戶端是否與伺服器相連。

該屬性允許使用者在用戶端與伺服器沒有串連的情況下有更多的控制。例如,在從用戶端提出請求起到伺服器作出響應,其間要用去很長一段時間的情況下,這就可能有助於確保在繼續處理指令碼之前用戶端仍是連通的。

Response IsClientConnected 屬性可以在ASP運行之時,可以對服務端與客氣端是否中斷連線作出判斷並返回true or false。這樣也避免使用者在訪問較佔用資源的頁面時,因為使用者的重新重新整理或關閉頁面時,服務端程式還在繼續執行,而導致伺服器資源沒有被即時釋放。

if IsConnectedAfter(10) then
Response.Write "<div class=itxt>查詢逾時,請稍後重試!</DIV>"
Response.End
End If

函數如下:

Function IsConnectedAfter(Seconds)
Dim StartTime
Dim PauseTime

IsConnectedAfter = True
StartTime = Now

Do While DateDiff("s", StartTime, Now) < Seconds
PauseTime = Now
Do While DateDiff("s", PauseTime, Now) < 1
'Do Nothing
Loop
Response.Write ""
If Response.IsClientConnected = False then
IsConnectedAfter = False
Exit Function
End If

Loop
End Function
 



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.