G
Guest
I've have several webrequests being called consecutively from an .aspx that
return XML from sources outside the company. When the page runs it can take
anywhere between 30-60 seconds.
I heard about making webrequests asynchronosly and found:
http://samples.gotdotnet.com/quickstart/howto/doc/ASPXNet/GETAsync.aspx
I modified the code to add a couple requests right after each other as
listed below.
It worked but...
1.) What is the drawback of this technique in terms of performance in the
long run?
2.) Is there a way to determine when all of these webrequests complete and
just flush the response instead of waiting for the Thread.Sleep to complete?
HttpWebRequest wreq;
IAsyncResult r;
wreq = (HttpWebRequest) WebRequest.Create("http://somexmlsource1");
r = (IAsyncResult) wreq.BeginGetResponse(new
AsyncCallback(this.RespCallback), wreq);
wreq = (HttpWebRequest) WebRequest.Create("http://somexmlsource2");
r = (IAsyncResult) wreq.BeginGetResponse(new
AsyncCallback(this.RespCallback), wreq);
wreq = (HttpWebRequest) WebRequest.Create("http://somexmlsource3");
r = (IAsyncResult) wreq.BeginGetResponse(new
AsyncCallback(this.RespCallback), wreq);
Thread.Sleep(30000); <!--Wait 30 seconds to allow requests to complete
return XML from sources outside the company. When the page runs it can take
anywhere between 30-60 seconds.
I heard about making webrequests asynchronosly and found:
http://samples.gotdotnet.com/quickstart/howto/doc/ASPXNet/GETAsync.aspx
I modified the code to add a couple requests right after each other as
listed below.
It worked but...
1.) What is the drawback of this technique in terms of performance in the
long run?
2.) Is there a way to determine when all of these webrequests complete and
just flush the response instead of waiting for the Thread.Sleep to complete?
HttpWebRequest wreq;
IAsyncResult r;
wreq = (HttpWebRequest) WebRequest.Create("http://somexmlsource1");
r = (IAsyncResult) wreq.BeginGetResponse(new
AsyncCallback(this.RespCallback), wreq);
wreq = (HttpWebRequest) WebRequest.Create("http://somexmlsource2");
r = (IAsyncResult) wreq.BeginGetResponse(new
AsyncCallback(this.RespCallback), wreq);
wreq = (HttpWebRequest) WebRequest.Create("http://somexmlsource3");
r = (IAsyncResult) wreq.BeginGetResponse(new
AsyncCallback(this.RespCallback), wreq);
Thread.Sleep(30000); <!--Wait 30 seconds to allow requests to complete