Wait for HttpWebRequest.BeginGetResponse to finish in Windows Phone 7

后端 未结 6 2069
星月不相逢
星月不相逢 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条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-10 21:02

    This just takes a bit of a shift in thinking away from blocking/waiting to thinking in async terms on the WP7 platform. The result is the user is always able to interact with the UI.

    Move a call to your completion code (writeline in this case) into your CompletedEventHandler and for any UI updates marshall back to the UI thread with

    Dispatcher.BeginInvoke( () => { /* your UI update code */ } )
    

    If there are any UI elements that should not be interacted with while your async op is executing then these controls can be hidden or disabled for the interim.

提交回复
热议问题