13 Comments Already

commenter
Willi Firulais Said,
May 24th, 2009 @2:55 pm  

Greatp post. Exactly what is missing in silverlight.

commenter
June 5th, 2009 @1:14 pm  

Environment.TickCount: Gets the number of milliseconds elapsed since the system started. Not actual ticks.

Therefore, instead of new TimeSpan(GetCurrentElapsed()); it should be TimeSpan.FromMilliseconds(GetCurrentElapsed());

And you need to remove the divide by TimeSpan.TicksPerMilliseconds

With those changes this is a great class. Thanks for the code.

commenter
Aaron Said,
June 6th, 2009 @4:05 pm  

I’m not sure why you’re suggesting those changes Chad?

commenter
Pospa Said,
June 26th, 2009 @4:19 am  

There is an error in this implementation. Because TimeSpan.TicksPerMillisecond in mos of cases does not corespondent with ticks/s used for Environment.TickCount computing. You should to review your code.

commenter
Aaron Said,
June 30th, 2009 @7:39 pm  

Popsa — if that’s the case, what would the right answer be? The documentation doesn’t lead me to believe it’s wrong, and that would be an inconsistency in the framework.

commenter
Sree Said,
July 25th, 2009 @10:48 pm  

Thanks for the code. I could not make it work as is but Chad Riddle’s comments worked for me.

Sree

commenter
Rui Fan Said,
August 5th, 2009 @4:15 am  

Pospa and Chad Riddle are saying the samething.
Environment.TickCount is the milliseconds.
From MSDN:
TickCount is different from the Ticks property, which is the number of 100-nanosecond intervals that have elapsed since 1/1/0001, 12:00am.

commenter
Vincent Said,
April 2nd, 2010 @8:40 am  

There is a mistake. Has been said 3 times by now. this is the 4th. The fact you say the documentation leads you to think its correct, suggest you haven’t tested it nor read the documentation correctly.

http://msdn.microsoft.com/en-us/library/system.environment.tickcount.aspx

Clearly states it returns a value in milliseconds and not ticks.

Other then that, a big thanks for the code :) Works fine after some minor bug fixing

commenter
Vincent Said,
April 2nd, 2010 @8:46 am  

Fixed functions:

// Timespan expects the value indiciated as 100ns .. thats 1 / 10000 of a ms.
public TimeSpan Ellapsed
{
get { return new TimeSpan( GetCurrentElapsed() * 10000 ); }
}

// GetCurrentElapsed() returns the MS already, no need to adjust that
public long EllapsedMilliseconds
{
get { return GetCurrentElapsed(); }
}

// getting value in milliseconds, gotta recalculate to turn it into ticks
public long EllapsedTicks
{
get { return GetCurrentElapsed() * TimeSpan.TicksPerMillisecond; }
}

commenter
Aaron Said,
April 2nd, 2010 @10:24 am  

I’ve updated the code, and tested it. Thanks all for the suggestions. Not sure why my tests worked when I wrote it.

commenter
claudio Said,
April 24th, 2010 @2:19 pm  

Hi,
This class will be used in my solution by files shared between Silverlight and .NET 4.0.
So for compatibility issue, you should correct the word Ellapsed with Elapsed. It’s just cosmetic, but it can produce compilation problem in case of shared code.
Anyway Thanx
-Claudio

commenter
Aaron Said,
April 29th, 2010 @3:02 pm  

@claudio: Whoops! Must have done a search/replace and managed to spell it wrong. Need to spell check my APIs! :) I’ve fixed the problem. Thanks for the heads-up!

Pingback & Trackback

Related Post

Please Leave Your Comments Below

Please Note: All comments are moderated, so it may take some time before your comment appears.