【问题标题】:Progress info using HttpClient使用 HttpClient 的进度信息
【发布时间】:2014-07-18 14:07:38
【问题描述】:

我想在 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() 方法,一直等到整个下载完成。

【问题讨论】:

  • 也许你可以看看ManualResetEvent (msdn.microsoft.com/en-us/library/…)
  • 您何时以及如何调用 CheckProgress()?
  • 哈哈,我也是……我很困惑。你有完整的代码吗?

标签: c# asynchronous httpclient windows-phone-8.1


【解决方案1】:

我的问题得到了解决,但这只是我的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;   
} 

它工作正常。希望它会帮助有人欢呼:)

【讨论】:

  • zetcode.com/csharp/httpclient 中使用的存储字节呢?我的意思是,您的代码看起来有点不同。一旦调用 httpClient.GetAsync();方法
猜你喜欢
  • 1970-01-01
  • 2021-07-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多