0

I've got application page where is view from street camera. Photo form camera is refreshing about every 30 sec.
I created a button which is used to refresh photo.
I want to add progress indicator which will be show every time when photo is downloading.
I don't know how and where exactly I have to add code.
I tried many examples but fail.
Because I don't really understand how to turn it on and off.

public void downloading()
{
    WebClient webClient = new WebClient();
    webClient.OpenReadCompleted += new   OpenReadCompletedEventHandler(ImageOpenReadCompleted);
    webClient.OpenReadAsync(new Uri("http://przeprawa.swi.pl/cgi-bin/kam.cgi?6&1399042906515&" + Guid.NewGuid()));
}
private void ImageOpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
    if (!e.Cancelled && e.Error == null)
    {
        BitmapImage bmp = new BitmapImage();
        bmp.SetSource(e.Result);
        image1.Source = bmp;
    }
}
public void Refresh(object sender, EventArgs e)
{
    downloading();
}
csharpwinphonexaml
  • 3,659
  • 10
  • 32
  • 63
GarryMoveOut
  • 377
  • 5
  • 19
  • This may help : http://stackoverflow.com/questions/9459225/asynchronous-file-download-with-progress-bar – Shmwel May 04 '14 at 13:18

1 Answers1

0

Make this change to your code:

public void downloading()
{
    WebClient webClient = new WebClient();
    webClient.OpenReadCompleted += new   OpenReadCompletedEventHandler(ImageOpenReadCompleted);
    webClient.OpenReadAsync(new Uri("http://przeprawa.swi.pl/cgi-bin/kam.cgi?6&1399042906515&" + Guid.NewGuid()));
    var _progressIndicator = new ProgressIndicator
        {
            IsIndeterminate = true,
            IsVisible = true,
            Text = "Downloading...",
        };
    SystemTray.SetProgressIndicator(this, _progressIndicator);
}
private void ImageOpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
    if (!e.Cancelled && e.Error == null)
    {
        BitmapImage bmp = new BitmapImage();
        bmp.SetSource(e.Result);
        image1.Source = bmp;
        var _progressIndicator = new ProgressIndicator
        {
            IsVisible = false,
        };
        SystemTray.SetProgressIndicator(this, _progressIndicator);
    }
}
public void Refresh(object sender, EventArgs e)
{
    downloading();
}
csharpwinphonexaml
  • 3,659
  • 10
  • 32
  • 63