How to read a web page synchronously using WP7
I'm having some issues reading a web page synchronously in a XNA game for WP7. I was trying to do something like this: http://www.csharp411.com/read-a-web-page-in-c/
Unfortunately the method WebClient::DownloadString is not availab开发者_运维技巧le for WP7 and if I use HttpWebRequest the method GetResponse() is not available either.
Is there an easy alternative for this? Thanks!
It is by design, that no synchronous networking API's are available for WP7. This helps keep applications responsive by not blocking the UI thread.
You will need to use the asynchronous API's, for instance WebClient::BeginDownloadString()
.
You should design your application to work asynchronously, but if you really, really must, is should be relatively easy to wrap a set of async calls in a method that waits for the result synchronously.
You're specifically not supposed to do this in WP7. If you do, your application would block and it would eventually be shut down by the OS. You need to do this asynchronously and you will get better UI response this way anyway.
精彩评论