首先我创建了一个完整文件的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);
}
}
任何帮助或方向表示赞赏。
我想尝试一些如果不工作生病试试你的方法!谢谢 –
您的建议是正确的。谢谢 –