使用进展信息的HttpClient [英] Progress info using HttpClient

查看:165
本文介绍了使用进展信息的HttpClient的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Windows手机8.1 Silverlight中使用Windows.Web.Http.HttpClient实施进度条。

I wanted to implement progress bar using 'Windows.Web.Http.HttpClient' in Windows phone 8.1 silverlight.

编辑: - 第一回合 -

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.
}

再来尝试: - 但是,让异常在错误的时间委托调用

One More attempt :- But getting the Exception 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()方法,以保持等到整个下载完成。

All, I wanted is to stop the CheckProgress() Method to keep waiting till the whole download completed.

任何能帮助我在这一个。任何帮助是AP preciated欢呼:)

Can any help me out in this one. Any help is appreciated cheers :)

推荐答案

我得到了我的问题的解决方案,但它只是在我的第二次尝试有点怀念

I got the solution of my problem but it is just a little miss in my Second Attempt.

private async Task CheckProgress()
{
    var df = httpClient.GetAsync(new Uri(uriString, UriKind.Absolute))

    df.Progress = (res, progress) =>
    { 
       // no separate event handler.
    }

    await df;   
} 

这仅仅是工作的罚款。希望这将有助于有人欢呼:)

It is just working fine. Hope it will help someone cheers:)

这篇关于使用进展信息的HttpClient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆