Showing progress after every percent for file download using backgroundtransfer

שאלה Showing progress after every percent for file download using backgroundtransfer

  • יום חמישי 16 אוגוסט 2012 07:09
     
     

    I am showing thumbnail for magazines in a list and added a download button for each magazine. One can download the magazine by clicking on download button. I want to show a label which will show the progress after every percent i.e 1%, 2%,3% so on... and that too for each magazine separately. how can I acheive this?

    I was looking at Background Transfer sample  provided in the samples but I guess it shows the % after a certain time. How can I change it to show the progress % as I want?

כל התגובות

  • יום חמישי 16 אוגוסט 2012 11:32
    מנחה דיון
     
     
  • יום רביעי 22 אוגוסט 2012 18:02
    מנחה דיון
     
     

    Hi,

    We’ve been discussing our original answer here, and have a new recommendation.  Background Downloader gives you a substantial amount of functionality with a very straightforward API.  HttpClient is a lower-level API; it can potentially do exactly what you want to achieve, but you’ll need to do more work to fit it to your program. Considering what needs to be achieved – I think Background Downloader seems to be a good option from a performance and coding time perspective with a trade-off for displaying % downloaded intervals.

    -Sagar

  • יום שישי 24 אוגוסט 2012 10:57
     
     

    Sagar

    Sorry for delayed reply , got busy with other things.

    Good to know that I am on the right track but my query still remain the same. How can I shorten the time for the callback loop and also If there are multiple downloads and progress bar for each download, which event handler I will need to invoke to update the progress value on each progress bar?

  • יום חמישי 27 דצמבר 2012 17:34
     
      קוד כלול
    private void DownloadProgress(DownloadOperation download)
            {
                MarshalLog(String.Format("Progress: {0}, Status: {1}", download.Guid, download.Progress.Status));
    
                double percent = 100;
                if (download.Progress.TotalBytesToReceive > 0)
                {
                    percent = download.Progress.BytesReceived * 100 / download.Progress.TotalBytesToReceive;
                }
    
                MarshalLog(String.Format(" - Transfered bytes: {0} of {1}, {2}%",
                    download.Progress.BytesReceived, download.Progress.TotalBytesToReceive, percent));
    
                if (download.Progress.HasRestarted)
                {
                    MarshalLog(" - Download restarted");
                }
    
                if (download.Progress.HasResponseChanged)
                {
                    // We've received new response headers from the server.
                    MarshalLog(" - Response updated; Header count: " + download.GetResponseInformation().Headers.Count);
    
                    // If you want to stream the response data this is a good time to start.
                    // download.GetResultStreamAt(0);
                }
            }

    private void MarshalLog(string value)
            {
                var ignore = this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    Log(value);
                });
            }
    
            private void Log(string message)
            {
                textBlock.Text += message + "\r\n";
            }


    • נערך על-ידי Wilson Vargas יום חמישי 27 דצמבר 2012 17:35 Error
    • נערך על-ידי Wilson Vargas יום חמישי 27 דצמבר 2012 17:36
    •