2016-03-03 88 views
0

首先我创建了一个完整文件的gist以供参考。处理多个确定进度条

我想什么是上传独家确定的进度栏的多个文件(每个文件单独的进度条)

我已经成功地实现了上传进度和我能够得到独立的进度百分比为每个文件上看到线164

Debug.WriteLine(String.Format(CultureInfo.CurrentCulture, "Progress: {0}, Status: {1}", upload.Guid, currentProgress.Status)); 

我目前通过Grid上市文件装订线117

FA.Add(new FilesAttached 
{ 
    Filename = fname, 
    FileSize = fsize, 
    Percent = upload.Progress.BytesSent.ToString() 
}); 
await coreDispatcher.RunAsync(CoreDispatcherPriority.Normal, 
    () => 
      { 
       attachments_all.ItemsSource = FA; 
      }); 

的proble所见M I有是进展并没有改变,我相信确切的摘录,其中有什么不妥,这是

private async Task HandleUploadAsync(UploadOperation upload, bool start, string fname, string fsize) 
     { 
      CoreDispatcher coreDispatcher = Window.Current.Dispatcher; 
      try 
      { 

       percent.Add("0"); 
       Debug.WriteLine("Running: " + upload.Guid, ""); 
       FA.Add(new FilesAttached 
       { 
        Filename = fname, 
        FileSize = fsize, 
        Percent = upload.Progress.BytesSent.ToString() 
       }); 
       await coreDispatcher.RunAsync(CoreDispatcherPriority.Normal, 
          () => 
          { 
           attachments_all.ItemsSource = FA; 
          }); 
       Progress<UploadOperation> progressCallback = new Progress<UploadOperation>(UploadProgress); 
       if (start) 
       { 
        // Start the upload and attach a progress handler. 
        await upload.StartAsync().AsTask(cts.Token, progressCallback); 
       } 
       else 
       { 
        // The upload was already running when the application started, re-attach the progress handler. 
        await upload.AttachAsync().AsTask(cts.Token, progressCallback); 
       } 

       ResponseInformation response = upload.GetResponseInformation(); 

       Debug.WriteLine(String.Format(CultureInfo.CurrentCulture, "Completed: {0}, Status Code: {1}", upload.Guid, 
        response.StatusCode), ""); 
      } 
      catch (TaskCanceledException) 
      { 
       Debug.WriteLine("Canceled: " + upload.Guid, ""); 
      } 
      catch (Exception ex) 
      { 
       if (!IsExceptionHandled("Error", ex, upload)) 
       { 
        throw; 
       } 
      } 
     } 
     private void UploadProgress(UploadOperation upload) 
     { 
      // UploadOperation.Progress is updated in real-time while the operation is ongoing. Therefore, 
      // we must make a local copy at the beginning of the progress handler, so that we can have a consistent 
      // view of that ever-changing state throughout the handler's lifetime. 
      BackgroundUploadProgress currentProgress = upload.Progress; 

      Debug.WriteLine(String.Format(CultureInfo.CurrentCulture, "Progress: {0}, Status: {1}", upload.Guid, 
       currentProgress.Status)); 
      FilesAttached newFA = new FilesAttached(); 
      newFA.RaisePropertyChanged("Percent"); 
      double percentSent = 100; 
      if (currentProgress.TotalBytesToSend > 0) 
      { 
       percentSent = currentProgress.BytesSent * 100/currentProgress.TotalBytesToSend; 

      } 

      Debug.WriteLine(String.Format(CultureInfo.CurrentCulture, 
       " - Sent bytes: {0} of {1} ({2}%)", currentProgress.BytesSent, 
       currentProgress.TotalBytesToSend, percentSent)); 

      if (currentProgress.HasRestarted) 
      { 
       Debug.WriteLine(" - Upload restarted"); 
      } 

      if (currentProgress.HasResponseChanged) 
      { 
       // We've received new response headers from the server. 
       Debug.WriteLine(" - Response updated; Header count: " + upload.GetResponseInformation().Headers.Count); 

       // If you want to stream the response data this is a good time to start. 
       // upload.GetResultStreamAt(0); 
      } 
     } 

任何帮助或方向表示赞赏。

回答

1

我有一个非常相似的下载管理器。你必须改变一下逻辑。 我有一个SingleDownload.cs类和一个DownloadManager.cs。

在单个下载: 我实现INotifyPropertyChanged和我有一个像TitleDownloadLinkProgress等我SingleDownload管理下载所以它很容易从进展内更改的属性。我也有方法,如Start(),Stop(),Dispose()

在DownloadManager.cs(也是一个页面)我有一个ObservableList<SingleDownload> downloads这绑定到一个ListView与进度条绑定到进度。它像一个魅力。

因此,创建一个类前。 SingleUpload将管理一个上传与其进展,并创建一个上传列表并将其绑定到您的attachments_all

+0

我想尝试一些如果不工作生病试试你的方法!谢谢 –

+0

您的建议是正确的。谢谢 –