How to get a high resolution timestamp?
Last post 05-12-2008 4:53 PM by Karol Kolenda. 2 replies.
Sort Posts:
05-11-2008 3:42 PM
How to get a high resolution timestamp?

Hi guys,

I've got the following problem: I'm porting a DispatcherTimer-based animation from WPF to Silverlight. It's time-based animation so in WPF I used Stopwatch to get a high-res timestamp for frame calculations. My first attempt was based on Environment.TickCount but the animation was not smooth enough. However with Stopwatch everything was perfect.

Unfortunatelly Silverlight does not contain Stopwatch class in System.Diagnostics hence the question: is there any way to get something more precise than Environment.TickCount in Silverlight?

Thanks 

PS: Please note that I'm not complaining about DispatcherTimer - it's really fast. The only problem is that I cannot measure correctly the intervals between Tick events.

Karol Kolenda

Joined on 04-24-2008
Posts 4
05-12-2008 2:40 AM
Marked as Answer
Re: How to get a high resolution timestamp?

The problem is TickCount whose resolution is CPU dependent.  How about a timer or a fake animation to give you more accurate clocks?

(If this has answered your question, please "Mark as Answer")

Shawn Wildermuth
C# MVP, MCSD, Speaker and Author

Silverlight 2 Workshop
May 12-14, 2008 - Atlanta, GA
May 28-30, 2008 - San Francisco, CA
http://www.silverlight-tour.com

swildermuth

Joined on 10-13-2003
Atlanta, GA
Posts 1,058
05-12-2008 4:53 PM
Re: How to get a high resolution timestamp?

 Thanks Shawn for your help, a fake "animation" did the trick. I created an empty storyboard, set duration to something big (like one day or so) and used Storyboard.GetCurrentTime(myStoryboard) to get precise readings.

 

Karol Kolenda

Joined on 04-24-2008
Posts 4