2016-03-03 91 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

您的建議是正確的。謝謝 –