使用HttpClient获取进度信息
本文关键字:信息 获取 HttpClient 使用 | 更新日期: 2023-09-27 18:13:25
我想使用'Windows.Web.Http '实现进度条。Windows Phone 8.1 Silverlight.
Edit: First Attempt:
private async Task CheckProgress()
{
var df = httpClient.GetAsync(new Uri(uriString, UriKind.Absolute)).Progress = Progress;
// here i want to stop the execution till whole content downloaded
// Reason to wait here
// this client download will be used by one more async method. so i need to wait here till the file completely downloaded.
// this whole is done in this method only ( requirement)
}
private void Progress(IAsyncOperationWithProgress<HttpResponseMessage, HttpProgress> asyncInfo, HttpProgress progressInfo)
{
// here i getting the progress value.
// i have already set a call back method that report the progress on the UI.
}
再次尝试:但是得到异常Invocation of delegate at wrong time.
private async Task CheckProgress()
{
var df = httpClient.GetAsync(new Uri(uriString, UriKind.Absolute))
df.Progress = Progress;
await df;
// here i want to stop the execution till whole content downloaded
}
:
所有,我想要的是停止CheckProgress()
方法保持等待,直到整个下载完成。
我得到了我的问题的解决方案,但它只是一个小失误在我的第二次尝试:
private async Task CheckProgress()
{
var df = httpClient.GetAsync(new Uri(uriString, UriKind.Absolute))
df.Progress = (res, progress) =>
{
// no separate event handler.
}
await df;
}