开发者

How to get synchronous HTTP response?

I write a class to handle the request to web. And it has a method which is using WebClient actually to do the main job. When the DownloadStringCompleted method has been done, I want to return the value of the response.

I want to use that like this:

// the pubTimeLine() method returns the value 
// of开发者_JS百科 the request to the web using WebClient      
textBlock1.DataContext = wp.pubTimeLine(url);

How to make it? Or how to get the synchronous response of HTTP request?


You should never make synchronous network calls, it will freeze up your UI (and therefore your phone) which is a very bad user experience.

Instead do it asynchronously, something like:

wp.pubTimeLine(url, result => textBlock1.DataContext = result);

Where the second parameter is a lambda expression containing the callback that is called when the pubTimeLine method is done executing asynchronously.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜