Reputation: 309
Im creating a download speed test, and im downloading a 800megabit file to a Byte[] in a memory stream with
webClient.DownloadDataAsync(new Uri(link), memStreamArray);
How can i check how many bits are in the memStreamArray while downloading? I need this so i can do a calculation on size / time to get the speed in realtime.
Im planing on performing this calculation in the webClient.DownloadProgressChanged event.
Upvotes: 2
Views: 2052
Reputation: 6627
1 Byte = 8 bits and you have a byte arrray. Count how many bytes to you have in the array an multiply by 8. Or is it a trick question?
Upvotes: 2
Reputation: 161012
You need a DownloadProgressChanged event handler for this. The second parameter in the DownloadDataAsync
method is just an object you can retrieve in your callback UserState variable, it's just pass-through - you probably have no use for it in your scenario.
WebClient webClient = new WebClient();
webClient.DownloadProgressChanged += delegate(object sender, DownloadProgressChangedEventArgs e)
{
Console.WriteLine(e.BytesReceived);
};
webClient.DownloadDataAsync(new Uri(link));
Upvotes: 3