Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to determine FPS in a C# WPF program

Tags:

c#

wpf

frame-rate

I'm writing an application for a touch table using WPF and C#. (And, I'm not terribly familiar with WPF. At all.) We suspect we're not getting the framerate we're "requesting" from the API so I'm trying to write my own FPS calculator. I'm aware of the math to calculate it based on the internal clock, I just don't know how to access a timer within the Windows/WPF API.

What library/commands do I need to get access to a timer?

like image 970
chaosTechnician Avatar asked Dec 22 '22 21:12

chaosTechnician


2 Answers

I think you're looking for the StopWatch. Just initialize it and reset it with each start of your iteration. At the end of an iteration, do your calculation.

like image 41
Erik Noren Avatar answered Dec 24 '22 11:12

Erik Noren


Although you could use a DispatcherTimer (which marshalls its ticks onto the ui thread, causing relativity problems), or a System.Threading.Timer (which might throw an exception if you try to touch any UI controls), i'd recommend you just use the WPF profiling tools :)

like image 61
Rob Fonseca-Ensor Avatar answered Dec 24 '22 10:12

Rob Fonseca-Ensor