Click here to Skip to main content
15,887,214 members
Home / Discussions / C#
   

C#

 
Questionusing a Func with dynamic parameters as a query: pros ? cons ? and a few other miscellaneous questions on Func Pin
BillWoodruff21-Oct-14 13:03
professionalBillWoodruff21-Oct-14 13:03 
AnswerRe: using a Func with dynamic parameters as a query: pros ? cons ? and a few other miscellaneous questions on Func Pin
Richard Deeming22-Oct-14 2:41
mveRichard Deeming22-Oct-14 2:41 
GeneralRe: using a Func with dynamic parameters as a query: pros ? cons ? and a few other miscellaneous questions on Func Pin
BillWoodruff22-Oct-14 6:19
professionalBillWoodruff22-Oct-14 6:19 
GeneralRe: using a Func with dynamic parameters as a query: pros ? cons ? and a few other miscellaneous questions on Func Pin
Richard Deeming22-Oct-14 6:38
mveRichard Deeming22-Oct-14 6:38 
GeneralRe: using a Func with dynamic parameters as a query: pros ? cons ? and a few other miscellaneous questions on Func Pin
BillWoodruff22-Oct-14 7:44
professionalBillWoodruff22-Oct-14 7:44 
Questionspeedtest.net Like result Pin
Jassim Rahma21-Oct-14 10:21
Jassim Rahma21-Oct-14 10:21 
AnswerRe: speedtest.net Like result Pin
Pete O'Hanlon21-Oct-14 10:26
mvePete O'Hanlon21-Oct-14 10:26 
GeneralRe: speedtest.net Like result Pin
Jassim Rahma21-Oct-14 10:31
Jassim Rahma21-Oct-14 10:31 
Sorry, let me ask it this way...

I tried this code. I am getting the download rate in the result but how can I calculate the speed just like speedtest.net.

for example: I tried below code and got 69kb/sec and when I try the same time on speedtest.net the result will show 1.69Mbps.

How can I display similar result?


C#
Uri URL = new Uri("http://www.jassimrahma.com/speedtest/1024kb.txt");
WebClient wc = new WebClient();
double starttime = Environment.TickCount;

// download file from the specified URL, and save it to C:\speedtest.txt
wc.DownloadFile(URL, @"C:\temp\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);
lblStatus.Text = "Download rate: " + kbsec + " kb/sec";
try
{
    // delete downloaded file
    System.IO.File.Delete(@"C:\temp\speedtest\speedtest.txt");
    // Response.Write("Done.");
}
catch
{
    // lblStatus.Text = "Couldn't delete download file.":

    // Response.Write("Couldn't delete download file.");
    // Response.Write("To delete the file yourself, go to your C-drive and look for the file 'speedtest.txt'.");
}



Technology News @ www.JassimRahma.com

GeneralRe: speedtest.net Like result Pin
PIEBALDconsult21-Oct-14 10:35
mvePIEBALDconsult21-Oct-14 10:35 
GeneralRe: speedtest.net Like result Pin
Bernhard Hiller22-Oct-14 22:52
Bernhard Hiller22-Oct-14 22:52 
GeneralRe: speedtest.net Like result Pin
PIEBALDconsult21-Oct-14 10:31
mvePIEBALDconsult21-Oct-14 10:31 
Questiontrying to use stored proc @fields in winforms with sql connection. Error procedure or function @Field expects parameter... Pin
Sam 910021-Oct-14 8:34
Sam 910021-Oct-14 8:34 
AnswerRe: trying to use stored proc @fields in winforms with sql connection. Error procedure or function @Field expects parameter... Pin
Richard Deeming21-Oct-14 8:47
mveRichard Deeming21-Oct-14 8:47 
AnswerRe: trying to use stored proc @fields in winforms with sql connection. Error procedure or function @Field expects parameter... Pin
PIEBALDconsult21-Oct-14 9:10
mvePIEBALDconsult21-Oct-14 9:10 
GeneralRe: trying to use stored proc @fields in winforms with sql connection. Error procedure or function @Field expects parameter... Pin
Sam 910021-Oct-14 9:53
Sam 910021-Oct-14 9:53 
GeneralRe: trying to use stored proc @fields in winforms with sql connection. Error procedure or function @Field expects parameter... Pin
PIEBALDconsult21-Oct-14 10:04
mvePIEBALDconsult21-Oct-14 10:04 
GeneralRe: trying to use stored proc @fields in winforms with sql connection. Error procedure or function @Field expects parameter... Pin
Sam 910021-Oct-14 11:38
Sam 910021-Oct-14 11:38 
GeneralRe: trying to use stored proc @fields in winforms with sql connection. Error procedure or function @Field expects parameter... Pin
PIEBALDconsult21-Oct-14 11:48
mvePIEBALDconsult21-Oct-14 11:48 
Answerproblem with multicolumncombo and bindingnavigator movenext ,... Pin
fatemehsoleimani21-Oct-14 4:58
fatemehsoleimani21-Oct-14 4:58 
AnswerRe: problem with multicolumncombo and bindingnavigator movenext ,... Pin
fatemehsoleimani21-Oct-14 21:43
fatemehsoleimani21-Oct-14 21:43 
QuestionHow to trigger coded UI tests from C# code or can I draft mstest commands and trigger through process.start? Pin
vinod chattergee21-Oct-14 1:06
vinod chattergee21-Oct-14 1:06 
AnswerRe: How to trigger coded UI tests from C# code or can I draft mstest commands and trigger through process.start? Pin
Eddy Vluggen21-Oct-14 6:10
professionalEddy Vluggen21-Oct-14 6:10 
GeneralRe: How to trigger coded UI tests from C# code or can I draft mstest commands and trigger through process.start? Pin
vinod chattergee23-Oct-14 19:18
vinod chattergee23-Oct-14 19:18 
GeneralRe: How to trigger coded UI tests from C# code or can I draft mstest commands and trigger through process.start? Pin
Eddy Vluggen24-Oct-14 1:35
professionalEddy Vluggen24-Oct-14 1:35 
QuestionImplementing SSO using SAML, C# Pin
shank07ct21-Oct-14 1:05
shank07ct21-Oct-14 1:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.