Search code examples
c#.netwinformsipbandwidth

How to get the throughput in C#


Hello I want to calculate the throughput through C# using HttpWebRequest.
I thought of requesting a big file (500KB) while running a System.Diagnostics.Stopwatch.
Then I could calculate the KB/s rate. I have 2 problems at this point:
1. How accurate is this going to be? Can I rely on it or should I just use another method?
2. How can I host the file on a URL I can hard-code without worrying about server-side problems? Could I somehow use a file with such a size already present preferably on googles or microsofts page?

Thanks in advance,
Alex


Solution

  • It's really not something you should rely on:

    • Your user's bandwidth is going to fluctuate depending on the time of day, how busy their ISP is, what other programs they have open using the connection...
    • As well as that, if you're doing this based on a file hosted on a server, the result you get will depend on how busy that server is.
    • If one of your users has a limit on how much data they can download, they might not thank you for making them download an extra file that they don't need.

    You'd be best asking your user to pick their connection type from a list (e.g. "Modem - 56kbps", "DSL - < 2Mbps"), and use that to estimate how much bandwidth you'll have available.