[thelist] MSXML DOMDocument: Asynchronous?

Cymbala, Greg Greg.Cymbala at Den.Galileo.com
Mon Apr 22 12:57:02 CDT 2002


Don't do this.  Your "FOR i = 0 TO 400000" loop will cause excessive CPU
utilization (100% probably).  It might be that because your CPU is busy
counting from 0 to 400000, it doesn't have any remaining CPU resources to
load the XML file.

Unfortunately, there's no native way in VBScript w/ ASP to "sleep" or
suspend execution for a specified amount of time.  There's a Windows API
call you can use, if you can get a DLL onto the server -- just put this into
a VB DLL, create the object and call object.GoToSleep lMilliseconds

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Sub GoToSleep(ByVal lMilliseconds As Variant)

    On Error Resume Next

    If IsNumeric(lMilliseconds) Then
        If CLng(lMilliseconds) > 0 Then
            Call Sleep(CLng(lMilliseconds))
        End If
    End If

End Sub


Another somewhat bizarre and probably-not-recommended way I found to do it
(without having to resort to a DLL) was this:

In your ASP page, do this:

<%
Dim oWSH
Set oWSH = Server.CreateObject("WScript.Shell")
' Creates a new process that executes wait.vbs.
' 2000 is an command-line argument
' The 10 argument of the run method tells WSH "Sets
' the show state based on the state of the program
' that started the application."
' The True argument of the run method tells the WSH object
' to wait until the process ends until it returns.
' Sleep for 2 seconds:
oWSH.Run Server.MapPath("./wait.vbs 2000"), 10, True
Set oWSH = Nothing
%>

Then, create the wait.vbs file.  It contains:

' BEGIN FILE
Dim lWaitTime, objArgs

Set objArgs = WScript.Arguments

If IsNumeric(objArgs(0)) Then
	If CLng(objArgs(0)) > 0 Then
		lWaitTime = objArgs(0)
	Else
		lWaitTime = 0
	End If
Else
	lWaitTime = 0
End If

Set objArgs = Nothing

WScript.Sleep lWaitTime

WScript.Quit 12
' END FILE

This is probably not a good thing to do, but it worked for me once in a
pinch.

HTH,
Greg

-----Original Message-----
From: Tab Alleman [mailto:Tab.Alleman at realmetros.com]
Sent: Monday, April 22, 2002 10:34 AM
To: thelist at lists.evolt.org
Subject: [thelist] MSXML DOMDocument: Asynchronous?



 Anyone successfully used this object asynchronously?  Willing to share the
code, or at least tell me if mine has a problem?  All I want is to start
downloading a DOMDocument asynchronously, and if it doesn't load in a
certain period of time, to forget it (and presumably do something else).

Here's the code I'm using, but according to what I'm printing on the screen,
the readystate of the object starts at 3 and stays that way the whole time,
apparently no matter how long I wait.

<%
OPTION EXPLICIT

Dim i
i = 0
Dim GetStr

GetStr =
"http://res.amadeus.net/pl/tab/us/a.xmt?SESSION_ID=&FCT=HARA0&LANGUAGE=U
S&SITE=RMC&CAPLUS_INDICATOR=TRUE" & _

"&HOTEL_CODE=ISM524&HOTEL_CHAIN_CODE=DI&IN_DATE=20020502&OUT_DATE=200205
03&OCCUPANCY=2"

Dim xmlRoomAvail
Set xmlRoomAvail = CreateObject("msxml2.DOMDocument.4.0")
xmlRoomAvail.async = true
xmlRoomAvail.load GetStr

FOR i = 0 TO 400000
	Response.Write("<h3>ReadyState " & i & " = " &
xmlRoomAvail.ReadyState & "</h3>")
	IF xmlRoomAvail.ReadyState = 4 THEN
		Exit FOR
	END IF
NEXT

Response.Write("<h3>Debug: " & Server.HTMLEncode(xmlRoomAvail.xml) &
"</h3>")
Response.Write("<h3>i =  " & i & "</h3>")
Set xmlRoomAvail = Nothing

%>


The information in this electronic mail message is sender's business
Confidential and may be legally privileged.  It is intended solely for the
addressee(s).  Access to this Internet electronic mail message by anyone
else is unauthorized.  If you are not the intended recipient, any
disclosure, copying, distribution or any action taken or omitted to be taken
in reliance on it is prohibited and may be unlawful.
The sender believes that this E-mail and any attachments were free of any
virus, worm, Trojan horse, and/or malicious code when sent. This message and
its attachments could have been infected during  transmission. By reading
the message and opening any attachments, the recipient accepts full
responsibility for taking protective and remedial action about viruses and
other defects. Galileo International is not liable for any loss or damage
arising in any way from this message or its attachments.





More information about the thelist mailing list