locked
Multiple download progress bar

    Question

  • I'm using background transfer sample to download files and i'm using the same code here:

    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj152726.aspx

    now how can i display multiple downloads progress bars for each download?


    here is method responsible for the progress bar of a download:


      private void ProgressCallback(DownloadOperation obj)
            {
                double progress
                    = ((double)obj.Progress.BytesReceived / obj.Progress.TotalBytesToReceive);
                if (thisprogress.Value < 100)
                {
                    gsc.sdg[index].Progress = progress * 100;
                }
            }
    

    Note that i'm using data binding for the downloads progress, but how can i differentiate between 2 download progress bars in my code?

    the index represents the position of the current download in the observable dictionary list, so making another download will stop the current progress bar and move to the last one and i don't this, i want both to download with their own progress in the same time. 


    Saturday, May 24, 2014 4:15 PM

Answers

  • Hi outsorts,

    Well, you want both of your progress bar update the download progress in the same time.

    How can i differentiate between 2 download progress bars in my code?

    -> Do you know the index for different DownloadOperation objects? If yes, you definitely can update the correct progress bar. I think in the tutorial, section "Enumerate persisted operations at start-up" has a clearly description for how to handle different download tasks.

    I think the sample for Background Transfer support multi-task download state update by monitor each download in a activeDownload list. I attach the code snippet here:

            private async Task DiscoverActiveDownloadsAsync()
            {
                activeDownloads = new List<DownloadOperation>();
    
                IReadOnlyList<DownloadOperation> downloads = null;
                try
                {
                    downloads = await BackgroundDownloader.GetCurrentDownloadsAsync();
                }
                catch (Exception ex)
                {
                    if (!IsExceptionHandled("Discovery error", ex))
                    {
                        throw;
                    }
                    return;
                }
    
                Log("Loading background downloads: " + downloads.Count);
    
                if (downloads.Count > 0)
                {
                    List<Task> tasks = new List<Task>();
                    foreach (DownloadOperation download in downloads)
                    {
                        Log(String.Format(CultureInfo.CurrentCulture,
                            "Discovered background download: {0}, Status: {1}", download.Guid,
                            download.Progress.Status));
    
                        // Attach progress and completion handlers.
                        tasks.Add(HandleDownloadAsync(download, false));
                    }
    
                    // Don't await HandleDownloadAsync() in the foreach loop since we would attach to the second
                    // download only when the first one completed; attach to the third download when the second one
                    // completes etc. We want to attach to all downloads immediately.
                    // If there are actions that need to be taken once downloads complete, await tasks here, outside
                    // the loop.
                    await Task.WhenAll(tasks);
                }
            }

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, May 26, 2014 9:22 AM
    Moderator