Answer the question
In order to leave comments, you need to log in
How to create a synchronous request in windows phone 8?
The bottom line is that the application loads data into JSON at startup and saves it to isolated storage. As it turned out in wp8 WebClient does not contain a synchronous request, only an asynchronous one.
It goes like this for me. JsonObj JsonObj = new JsonObj();
The constructor checks whether there is a data string in json in the isolated storage, if there is none, then a request is made to the server and the data is stored in the isolated storage and deserialized. and then, according to the idea, we work with the data.
JsonObj JsonObj = new JsonObj();
MainNewsList.ItemsSource = JsonObj.MAIN_NEWS;
NewsList.ItemsSource = JsonObj.NEWS;
MainNewsList.ItemsSource = JsonObj.MAIN_NEWS;
NewsList.ItemsSource = JsonObj.NEWS;
Answer the question
In order to leave comments, you need to log in
The answer to your question is: NO!
Explanation: DON'T DO IT!
Synchronous requests to the server were removed SPECIALLY, so that those who like to load data in the UI thread would not have such an opportunity.
Hang a progress bar for the loading time, and when the data is loaded, display them, there is nothing complicated about it. For syntactic sugar, you can also install Async CTP.
Take an Action in the class constructor
public JsonObj(Action callback)
{
//...
}
JsonObj JsonObj = new JsonObj(()=>
{
MainNewsList.ItemsSource = JsonObj.MAIN_NEWS;
NewsList.ItemsSource = JsonObj.NEWS;
});
You can download synchronously, but why?
For HttpClient (there is a nuget of the same name) there will be something like this: var client = new HttpClient(); var result = client.GetStringAsync(/*your url*/).Result;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question