我想在 Windows Phone 8.1 Silverlight 中使用“Windows.Web.Http.HttpClient”实现进度条。
编辑:第一次尝试:
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;
}
一切正常。
关于c# - 使用 HttpClient 的进度信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24827009/