Progress info using HttpClient

旧城冷巷雨未停 提交于 2019-12-11 02:53:30

问题


I wanted to implement progress bar using 'Windows.Web.Http.HttpClient' in 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.
}

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
} 

Question:

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


回答1:


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:)



来源:https://stackoverflow.com/questions/24827009/progress-info-using-httpclient

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!