How to time an Asychronous HttpWebRequest?
I am wondering if there is a way to time an Asyhcnronous WebRequest. I am using the HttpWRequest.BeginGetResponse(new AsyncCallback(UpdateItem), si); si = StoreInfo and is a class instance storing the Request,URL, and a stopwatch which I started). In the UpdateItem routine I get the stopwatch and stop it.
Problem is the stopwatch is running but the request is waiting to start the request, it has NOT actually made the request.
So I guess I need a way to start the stopwatch when the request actually begins(a thread starts on this request) OR somehow determine the time elapsed from the request/response? Don't thin开发者_如何转开发k there is a way.
Anyone have any ideas?
If you want to measure wallclock time, ie. time when the BeginGetResponse() was called, and when it completed, then what you are doing is right.
However, as you mentioned this does not actually give you the network time, where you measure the time between the first byte of HTTP request header written to network, and time to receive the first byte of response. This is not easy to measure using the API. You will have to do it manually using a network capture tool like Wireshark/Netmon.
精彩评论