首先我創建了一個完整文件的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);
}
}
任何幫助或方向表示讚賞。
我想嘗試一些如果不工作生病試試你的方法!謝謝 –
您的建議是正確的。謝謝 –