Recently I decided to work with Rx (Reactive Extensions) for Windows Phone 7 and I encountered some weird behavior.
For example, I have this piece of code:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://whatismyip.org/");
request.Method = "GET";
var x = from c in Observable.FromAsyncPattern<WebResponse>(request.BeginGetResponse, request.EndGetResponse)()
select c;
WebResponse r = x.First();
Debug.WriteLine(r.ContentType.ToString());
What I am trying to figure out is why when I reach the LINQ query, it hangs the UI and doesn’t go any further than this. Any ideas?
AFAIK, call to First is blocking, so execution will be resumed only after receiving response.
Try replace it with