下面的代码在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);
}
答案 0 :(得分:1)
HttpClient不支持进度报告
最好的方法是使用Windows.Web.Http.HttpClient
代替System.Net.Http.HttpClient
。第一个支持进步。
我在msdn
中DownloadProgressChanged
找不到活动HttpClient
尝试将webclient
用于DownloadProgress
。
Difference between httpclient vs webclient
如果您仍然需要httpclient
进度报告,则需要自己实施。Progress Bar with HttpClient
答案 1 :(得分:1)
我认为您应该使用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);
}