Does Windows Phone 7 support asynchronous programming?

I am creating a news reader application for wp7. I would like some background actions to take place, for example, writing downloaded content to isolated storage. Is there a way to do this without blocking the user interface thread?

The event DownloadStringCompleted WebClientis asynchronous, right? Can I just do it there?

+3
source share
4 answers

It is asynchronous, but it recommended that you do not do any non-trivial processing using WebClient, since this work will be performed in the user interface thread, as Indy correctly points out.

Webclient .

Dispatcher.BeginInvoke( () => { /* ui update code */ } );

, .

HttpWebRequest ( WebClient) (. ).

, , . Thread.Sleep(xxx), .

HttpWebRequest WebClient .

WebClient, HttpWebRequest Windows Phone 7

+3

, , , Dispatcher.BeginInvoke, . HttpWebRequest WebClient, WebClient . MSDN, , , .

0

, . , WP7.

0

WP7 , api , .

As noted in other answers, you should know that you need to update the interface through the user interface thread, you can use Dispatcher.BeginInvoke if you are working with code. If you use some MVVM style template, INotifyPropertyChanged events are automatically sent back to the UI thread, so you don’t have to worry about this (INotifyCollectionChanged from ObservableCollection for unknown reasons).

-1
source

Source: https://habr.com/ru/post/1772418/


All Articles