Wait for HttpWebRequest.BeginGetResponse to finish in Windows Phone 7

后端 未结 6 2084
星月不相逢
星月不相逢 2021-02-10 20:05

I\'m trying to use the async HttpWebRequest in Silverlight for Windows Phone. All works perfect until I get to the where I should call

private stati         


        
6条回答
  •  梦毁少年i
    2021-02-10 20:42

    To be honest, this isn't a good idea. Having the wait on the main (UI) thread will lock the phone up and create an unresponsive UI. It'll be better in the long run not to fight the async network access in WP7 and Silverlight, the code can be more complex in places and you end up having a lot of methods that take call backs, but having a more response UI is better than having it lock up.

    var request = WebRequest.CreateHttp(uri);
    
    request.BeginGetResponse(r =>
    {
        var reponse = request.EndGetResponse(r);
    
        // Do things response here
    }, null);
    
    // Let the method end and not wait
    

提交回复
热议问题