I have a problem with WebClient’s DownloadProgressChaned event in Mono.
The BytesReceived property does not seem to work. It is always returning a number which seems random to me and has no relation to the actual count of received bytes.
This code works perfectly fine in .NET, but in Mono (2.10.8, Windows), BytesReceived is “random” whenever DownloadProgressChanged gets fired…
ProgressPercentage does not work either.
using (WebClient wc = new WebClient())
{
AutoResetEvent r = new AutoResetEvent(false);
wc.DownloadProgressChanged += (sender, e) =>
{
Console.WriteLine(string.Format("Received: {0} of {1} ({2} %)", e.BytesReceived, e.TotalBytesToReceive, e.ProgressPercentage));
};
wc.DownloadDataCompleted += (sender, e) =>
{
if (e.Error != null)
{
Console.WriteLine(string.Format("Error: {0}", e.Error.Message));
}
else
{
Console.WriteLine("OK");
}
r.Set();
};
string url = @"http://someurl/somefile.pdf";
wc.DownloadDataAsync(new Uri(url));
r.WaitOne();
}
Any suggestions?
This looks like a bug that has already been fixed: https://bugzilla.xamarin.com/show_bug.cgi?id=2482.
I believe the latest Mono (2.10.9) has this fix included.