Click here to Skip to main content
11,805,604 members (53,576 online)
Rate this: bad
Please Sign up or sign in to vote.
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
namespace SpeedTest
    class Program
        static void Main(string[] args)
            Console.Title = "A simple speedtest app";
            // the URL to download a file from
            Uri URL = new Uri("");
            WebClient wc = new WebClient();
            Console.WriteLine("Welcome to this simple speedtest,\nwhich will test your download rate.");
            Console.WriteLine("Press any key to begin.");
            Console.WriteLine("\nDownloading file: 1024kb.txt...");
            Console.WriteLine("Note: This file will automatically be deleted after the test.");
            // get current tickcount 
            double starttime = Environment.TickCount;
            // download file from the specified URL, and save it to C:\speedtest.txt
            wc.DownloadFile(URL, @"C:\SpeedTest\SpeedTest\speedtest.txt");
            // get current tickcount
            double endtime = Environment.TickCount;
            // how many seconds did it take?
            // we are calculating this by subtracting starttime from endtime
            // and dividing by 1000 (since the tickcount is in miliseconds.. 1000 ms = 1 sec)
            double secs = Math.Floor(endtime - starttime) / 1000;
            // round the number of secs and remove the decimal point
            double secs2 = Math.Round(secs, 0);
            // calculate download rate in kb per sec.
            // this is done by dividing 1024 by the number of seconds it
            // took to download the file (1024 bytes = 1 kilobyte)
            double kbsec = Math.Round(1024 / secs);
            Console.WriteLine("\nCompleted. Statistics:\n");
            Console.WriteLine("1mb download: \t{0} secs ({1} secs)", secs2, secs);
            Console.WriteLine("Download rate: \t{0} kb/sec", kbsec);
            Console.WriteLine("\nPress any key to exit...");
            Console.WriteLine("Cleaning up... (deleting downloaded file)");
                // delete downloaded file
                Console.WriteLine("Couldn't delete download file.");
                Console.WriteLine("To delete the file yourself, go to your C-drive and look for the file 'speedtest.txt'.");
[Edit]Code block added, 'C#' and 'services' tag added, 'to' tag removed[/Edit]
Posted 22-Jan-13 7:09am
Edited 22-Jan-13 7:10am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I did as above but the following error message

Starting a second message loop on a single thread is not a valid operation. Use Form.ShowDialog instead.

in position
Application.Run(new Form1());

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 310
1 Richard Deeming 225
2 Sergey Alexandrovich Kryukov 170
3 Abhinav S 128
4 ppolymorphe 125
0 OriginalGriff 3,300
1 Maciej Los 1,990
2 KrunalRohit 1,907
3 CPallini 1,855
4 Richard MacCutchan 1,227

Advertise | Privacy | Mobile
Web01 | 2.8.151002.1 | Last Updated 22 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100