![]() |
|
[.NET] Download Speed Meter - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [.NET] Download Speed Meter (/showthread.php?tid=4359638) |
Download Speed Meter - SIM-1456245 - Jul 25, 2014 Hey people. I was bored and decided to (as always) over code a class for measuring download speeds. It will basically download a file and calculate the size of it the time it took to download and calculate the speed in a nice structure(bps, Kbps, Mbps, Gbps). In the example there is a link given to a file that is exactly 1.000.000 bytes big. I will have to note that this will give you BITS PER SECOND not BYTES PER SECONDS. And also it takes in measurement 1 Mb = 1000 Kb. You need to specify the URL in the New method as a argument. And when you want to measure, you need to call the Measure() method. When it finishes, the Complete() event will be risen. It has event arguments. It will give you the file size, time needed to download and a structure with the speed in 4 different measurements(bps, Kbps, Mbps, Gbps). The Error event is risen whenever there is a error, don't bitch about this, because I like to handle errors like that, and that's how I do it. There is also if you notice another method called SimpleMeasure(), that is basically the whole class in one very tiny method. It is not async, but for anyone that will say that it can be done shorter, I proved him right. Enough talking here is the code(example included): http://pastebin.com/Tj9m4ZzH UPDATE: There is not a string representation with the appropriate measurement represented as string in the event args as a text string variable. * - +Haze - Jul 25, 2014 Thanks for this ma niggs, I'm sure this would become useful soon. * - VirinomTR - Jul 25, 2014 Nice share man. Small modification for auto unit set like if speed is upper than 1024 kbps show 1 mbps this make more useful. When go home i gonna do this and post here or you can do this. Really useful for autoupdate systems thanks again. * - SIM-1456245 - Jul 25, 2014 (Jul 25, 2014 04:49 PM)VirinomTR Wrote: Nice share man. Small modification for auto unit set like if speed is upper than 1024 kbps show 1 mbps this make more useful. When go home i gonna do this and post here or you can do this. Tnx for the suggestion. I already have that in another project. Let me just implement it here. Done, Implemented string capability. * - SaketSaket - Jul 26, 2014 Nice... very useful ;) Will look into code to learn new thing ;) * - zeroexp - Jul 26, 2014 Nice share. I see that there's a lot of work in the class. Good job. * - Cairns - Jul 26, 2014 Decent enough by WHY are you using a loop to update? lol use events and this would be far better. Thanks for the share * - SIM-1456245 - Jul 26, 2014 (Jul 26, 2014 05:43 AM)Cairns Wrote: Decent enough by WHY are you using a loop to update? lol use events and this would be far better. Wrong thread obviously. There is not a single loop here, and it works all with events. * - Cairns - Jul 26, 2014 wth is this Code Sub Main()* - SIM-1456245 - Jul 26, 2014 (Jul 26, 2014 09:20 AM)Cairns Wrote: wth is this Lol, I just had a little bit more fun than I should had with the console colors. |