Click here to Skip to main content
15,886,422 members
Home / Discussions / C#
   

C#

 
GeneralRe: same enumeration, different results? Pin
CCodeNewbie20-Mar-12 0:48
CCodeNewbie20-Mar-12 0:48 
GeneralRe: same enumeration, different results? Pin
CCodeNewbie20-Mar-12 0:48
CCodeNewbie20-Mar-12 0:48 
GeneralRe: same enumeration, different results? Pin
PIEBALDconsult20-Mar-12 3:34
mvePIEBALDconsult20-Mar-12 3:34 
GeneralRe: same enumeration, different results? Pin
CCodeNewbie20-Mar-12 8:29
CCodeNewbie20-Mar-12 8:29 
GeneralRe: same enumeration, different results? Pin
PIEBALDconsult20-Mar-12 11:03
mvePIEBALDconsult20-Mar-12 11:03 
GeneralRe: same enumeration, different results? Pin
CCodeNewbie20-Mar-12 12:08
CCodeNewbie20-Mar-12 12:08 
GeneralRe: same enumeration, different results? Pin
CCodeNewbie20-Mar-12 2:30
CCodeNewbie20-Mar-12 2:30 
GeneralRe: same enumeration, different results? Pin
Alan N20-Mar-12 3:39
Alan N20-Mar-12 3:39 
I'm glad you've come to a solution that you are happy with. One point that I'm not sure you appreciate is that the up time obtained from the performance counter and the TickCount are essentially the same value.

C#
private void CompareCounterAndTickCount() {
  using (PerformanceCounter ut = new PerformanceCounter("System", "System Up Time")) {
    ut.NextValue();
    TimeSpan counterUpTime = TimeSpan.FromSeconds(ut.NextValue());
    TimeSpan tickCountUpTime = TimeSpan.FromMilliseconds(Environment.TickCount);
    Console.WriteLine("Up Time");
    Console.WriteLine("  from performance counter {0}", counterUpTime);
    Console.WriteLine("  from tickcount           {0}", tickCountUpTime);
  }
}


On my system the duration reported by TickCount is ~0.2s longer than the performance counter's value which presumably just means the two counters do not share the same origin. Also note the use of the FromMilliseconds method to convert the TickCount to a TimeSpan, much simpler than your multistep calculation!

Alan.
GeneralRe: same enumeration, different results? Pin
CCodeNewbie20-Mar-12 8:33
CCodeNewbie20-Mar-12 8:33 
GeneralRe: same enumeration, different results? Pin
Alan N20-Mar-12 10:47
Alan N20-Mar-12 10:47 
GeneralRe: same enumeration, different results? Pin
CCodeNewbie20-Mar-12 12:00
CCodeNewbie20-Mar-12 12:00 
AnswerWrongMagicConstantInHorribleCodeException Pin
Luc Pattyn19-Mar-12 13:03
sitebuilderLuc Pattyn19-Mar-12 13:03 
GeneralRe: WrongMagicConstantInHorribleCodeException Pin
CCodeNewbie19-Mar-12 13:05
CCodeNewbie19-Mar-12 13:05 
GeneralRe: WrongMagicConstantInHorribleCodeException Pin
CCodeNewbie19-Mar-12 13:08
CCodeNewbie19-Mar-12 13:08 
Answerfloat maxDaysInInt=((float)int.MaxValue)/1000/60/60/24; Pin
Luc Pattyn19-Mar-12 13:25
sitebuilderLuc Pattyn19-Mar-12 13:25 
GeneralRe: float maxDaysInInt=((float)int.MaxValue)/1000/60/60/24; Pin
CCodeNewbie20-Mar-12 2:32
CCodeNewbie20-Mar-12 2:32 
AnswerRe: same enumeration, different results? Pin
Alan N19-Mar-12 13:29
Alan N19-Mar-12 13:29 
GeneralRe: same enumeration, different results? Pin
CCodeNewbie20-Mar-12 2:21
CCodeNewbie20-Mar-12 2:21 
QuestionQuery an Excel Spreadsheet Pin
PDTUM19-Mar-12 6:35
PDTUM19-Mar-12 6:35 
AnswerRe: Query an Excel Spreadsheet Pin
PIEBALDconsult19-Mar-12 8:26
mvePIEBALDconsult19-Mar-12 8:26 
GeneralRe: Query an Excel Spreadsheet Pin
PDTUM19-Mar-12 8:47
PDTUM19-Mar-12 8:47 
GeneralRe: Query an Excel Spreadsheet Pin
PIEBALDconsult19-Mar-12 12:04
mvePIEBALDconsult19-Mar-12 12:04 
AnswerRe: Query an Excel Spreadsheet Pin
Dave Kreskowiak19-Mar-12 9:10
mveDave Kreskowiak19-Mar-12 9:10 
GeneralRe: Query an Excel Spreadsheet Pin
PDTUM19-Mar-12 11:08
PDTUM19-Mar-12 11:08 
AnswerRe: Query an Excel Spreadsheet Pin
JOAT-MON19-Mar-12 13:27
JOAT-MON19-Mar-12 13:27 

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.