WebRequest - What Happens When ?

E

eBob.com

I thought I might save some time in a web application by caching some files
which are not likely to change very often. But I am wondering when the file
is actually fetched. Does anyone know when the bytes of the file are
actually transmitted in the sequence of statements below?

1) Dim URL As String = "http://path.jpg"
2) wrq = WebRequest.Create(URL)
3) wrp = DirectCast(wrq.GetResponse(), HttpWebResponse)
4) MsgBox("LastModified: " & wrp.LastModified)
5) MsgBox("ContentLength: " & wrp.ContentLength)
6) Dim sr As New StreamReader(wrp.GetResponseStream,
Encoding.GetEncoding(1252))
7) FileBytes = sr.ReadToEnd()

There's no point in keeping a cache if the bytes are actually transmitted
during the execution of line 3.

Thanks, Bob
 
F

Fred

in eBob.com wrote :
I thought I might save some time in a web application by caching some
files which are not likely to change very often. But I am wondering
when the file is actually fetched. Does anyone know when the bytes
of the file are actually transmitted in the sequence of statements
below?

1) Dim URL As String = "http://path.jpg"
2) wrq = WebRequest.Create(URL)
3) wrp = DirectCast(wrq.GetResponse(), HttpWebResponse)
4) MsgBox("LastModified: " & wrp.LastModified)
5) MsgBox("ContentLength: " & wrp.ContentLength)
6) Dim sr As New StreamReader(wrp.GetResponseStream,
Encoding.GetEncoding(1252))
7) FileBytes = sr.ReadToEnd()

There's no point in keeping a cache if the bytes are actually
transmitted during the execution of line 3.

Perhaps have a look at Method property (user HEAD)
 
A

AMercer

In some old code of mine that looks like yours, I have a comment that
GetResponse (ie your line 3) may block a noticeable amount of time. My
recollection is that none of the other statements take any significant amount
of time. Now maybe that is enough for your concerns, or maybe not. I went
to the documentation and was exasperated by the lack of clear language. So,
while I don't really know the specific answer to your question, maybe knowing
where your thread will block is enough for your purposes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top