In my WP7 application I loade some simple text data from the web.
string url = "home url";
var request = HttpWebRequest.Create(url);
var result = (IAsyncResult)request.BeginGetResponse(ResponseCallback, request);
And this is how I consume the data
private void ResponseCallback(IAsyncResult result)
{
var request = (HttpWebRequest)result.AsyncState;
var response = request.EndGetResponse(result);
using (var stream = response.GetResponseStream())
using (var reader = new StreamReader(stream))
{
var contents = reader.ReadToEnd();
Dispatcher.BeginInvoke(()=>
{
someLabelValue.Text = contents;
});
}
}
I added a indeterminate progress bar to my layout. Now I want to display it when my application is loading the data from the web.
How can I do that? Any ideas?
Simplest way, to see it working is to go and change the .Visiblility of the progress bar to Visible when you make the call (top code extract) and call .Visibility = Collapsed when it’s done (in the second sample, inside your BeginInvoke() block).