C# “如何处理事件”;“HttpClient”;在Windows Phone 8.1中

C# “如何处理事件”;“HttpClient”;在Windows Phone 8.1中,c#,windows-phone-8.1,C#,Windows Phone 8.1,下面的代码在WP8中工作,但是当使用WP8.1时,不会触发事件,处理事件的解决方案是什么 HttpClient wb = new HttpClient(); wb.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wcDownloadList_DownloadProgressChanged); if (itm.LinkUrl.StartsWith("http://www.youtube.com/watch?v="

下面的代码在WP8中工作,但是当使用WP8.1时,不会触发事件,处理事件的解决方案是什么

HttpClient wb = new HttpClient();
wb.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wcDownloadList_DownloadProgressChanged);
if (itm.LinkUrl.StartsWith("http://www.youtube.com/watch?v="))
{
    wb.OpenReadCompleted += new OpenReadCompletedEventHandler(wcYoutubeReadCompleted_OpenReadCompleted);
}
else
{
    wb.OpenReadCompleted += new OpenReadCompletedEventHandler(wcDownloadList_OpenReadCompleted);
}

HttpClient不支持进度报告

最好的方法是使用
Windows.Web.Http.HttpClient
而不是
System.Net.Http.HttpClient
。第一个支持进步

我在中的
HttpClient
中找不到事件
DownloadProgressChanged

尝试使用
webclient
进行
DownloadProgress


如果您仍然需要
httpclient
来进行报告,您需要自己实现。

我认为您应该使用
WebClient
而不是
httpclient

WebClient client = new WebClient ();
    Uri uri = new Uri(address);

    // Specify that the DownloadFileCallback method gets called 
    // when the download completes.
    client.DownloadFileCompleted += new AsyncCompletedEventHandler (DownloadFileCallback2);
    // Specify a progress notification handler.
    client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressCallback);
事件处理程序

private static void DownloadProgressCallback(object sender, DownloadProgressChangedEventArgs e)
{
// Displays the operation identifier, and the transfer progress.
Console.WriteLine("{0}    downloaded {1} of {2} bytes. {3} % complete...", 
    (string)e.UserState, 
    e.BytesReceived, 
    e.TotalBytesToReceive,
    e.ProgressPercentage);
}

开始下载的代码在哪里?您好,Peter Torr,首先介绍如何为httpclientk启动事件,但如何处理OpenReadCompleted EventWebClient在WP8.1 WinRtHello Rohit中不受支持,而在WP8.1 WinRt应用程序中不支持Eldho webclient。@我们建议为Httpclient启动Chinni。