I dunno if this is right though...because my program is returning values like 900 for the number of milliseconds per loop. Here is the code I'm using to time everything:
Expand|Select|Wrap|Line Numbers
- Stream strm = ftp.GetRequestStream();
- contentLen = fs.Read(buff, 0, buffLength);
- totalUploaded += contentLen;
- DateTime startTime = DateTime.Now;
- DateTime endTime;
- TimeSpan duration;
- while (contentLen != 0)
- {
- if (count == 32)
- {
- endTime = DateTime.Now;
- count = 0;
- duration = endTime - startTime;
- double inASec = (double)1000 / (double)duration.Milliseconds;
- uploadSpeed = Math.Round((double)64 * inASec, 2);
- startTime = DateTime.Now;
- }
- strm.Write(buff, 0, contentLen);
- contentLen = fs.Read(buff, 0, buffLength);
- percentDone = Math.Round((totalUploaded / finfo.Length) * 100, 2);
- textBox1.Text = "Uploaded " + totalUploaded + "/" + finfo.Length + " bytes - (" + percentDone + "%, " + uploadSpeed + "Kbps)";
- totalUploaded += contentLen;
- progressBar1.PerformStep();
- count++;
- Application.DoEvents();
- }
Is this a good way to do it?