0

The below code is working in WP8 but when coming to WP8.1 the Events are not fired, What is the solution for handle the Events.

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);
}
Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142
Devi Prasad
  • 829
  • 1
  • 11
  • 33

2 Answers2

1

HttpClient do not support Progress Reporting

The best way to go is using Windows.Web.Http.HttpClient instead of System.Net.Http.HttpClient. The first one supports progress.

I don't find an event DownloadProgressChanged in HttpClient in msdn

Try using webclient for DownloadProgress. Difference between httpclient vs webclient

If you still need a httpclient to Progress Reporting you need to implement yourself .Progress Bar with HttpClient

Community
  • 1
  • 1
Eldho
  • 7,795
  • 5
  • 40
  • 77
1

I think you should use WebClient instead of 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);

Event handler

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);
}
Ajay
  • 6,418
  • 18
  • 79
  • 130