"JezB" <je***********@blueyonder.co.uk> wrote in message
news:e8**************@tk2msftngp13.phx.gbl...
"Michael C" <no****@nospam.com> wrote in message
news:uZ*************@TK2MSFTNGP15.phx.gbl... "JezB" <je***********@blueyonder.co.uk> wrote in message
news:ek**************@TK2MSFTNGP11.phx.gbl...I do some peeking at files on the web in my program with code such as:
WebRequest wr = WebRequest.Create(url);
WebResponse r = wr.GetResponse();
I've noticed that the first time GetResponse is executed, it takes some
3 to 4 seconds. Repeating the same code in the same run is almost
immediate. So why the delay the first time this is executed on each
run? And can I do anything about it?
This is a very normal thing for PCs. Haven't you ever used a PC before
and noticed that doing practically *anything* takes longer the first time?
Michael
I've been using PCs for 20 years pal. Doesn't explain why the same url in
a web browser appears instantly (it's only a small text file) yet
GetResponse takes 4 seconds - there must be a reason for it, and I assume you don't
know it.
I see to possibilities.
1) There is a high overhead setting up the HTTP connection and the second
time its reused...
2) The immediate code is compiled the first time and the second time its
already present. That might be a side-effect of dotNET.
3) A round-trip to the server is expensive and the second time the cache is
used (not too likely that this is the case).
Of course combinations are possible too...
- Joris