Does WebClient.OpenFileAsync fire DownloadProgressChanged
According to
http://msdn.microsoft.com/en-us/library/system.net.webclient.downloadprogresschanged.aspx ,
OpenFileAsync should have DownloadProgressChanged firing when it makes progress.
I can't get him to shoot at all. However, fire works great with DownloadDataAsync and DownloadFileAsync.
Here's a simple example:
using System;
using System.Net;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
WebClient client = new WebClient();
client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
client.OpenReadAsync(new Uri("http://www.stackoverflow.com"));
Console.ReadKey();
}
static void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
Console.WriteLine("{0}% Downloaded", e.ProgressPercentage);
}
static void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
Console.WriteLine("Open Read Completed");
}
}
}
For me, the DownloadProgressChanged event never fires, although it changes to DownloadFileAsync or DownloadDataAsync and it does.
a source to share
I looked at the source of the framework, and as far as I can tell, OpenReadAsync never touches the stuff that triggers DownloadProgressChanged.
It does not call GetBytes like DownloadDataAsync and DownloadFileAsync, which in turn triggers the start of the event.
To get around this, I just used DownloadDataAsync, which fires an event and allows me to provide download feedback. It returns a byte array instead of the stream I want, but that's not a problem.
So my guess is MSDN, what's wrong here and OpenReadAsync doesn't trigger DownloadProgressChanged.
a source to share