Since WP7 HttpWebRequest does not support timeout, I\'m using a timer to implement the functionality. Below is an example. I call GetConnection() from a UI form. But ReadCal
Your code works as expected for me. When you call Abort() on a pending request, your ReadCallback is expected to fire. Then when you call EndGetResponse() you should get a WebException with Status=RequestCanceled.
Try this slightly modified code to see this in action:
private void ReadCallback(IAsyncResult asynchronousResult)
{
_stopTimer = true;
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
try
{
var m_response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
System.Diagnostics.Debug.WriteLine("Success");
}
catch (WebException exc)
{
System.Diagnostics.Debug.WriteLine(exc.Status);
}
}
See also on MSDN: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.abort(v=VS.95).aspx
"The Abort method cancels a request to a resource. After a request is canceled, calling the BeginGetResponse, EndGetResponse, BeginGetRequestStream, or EndGetRequestStream method causes a WebException with the Status property set to RequestCanceled."