First of all, did you know that Microsoft provides a free diagnostic tool that will tell you the frame rate with which WPF refreshes the screen? I think if you are not sure that you get the frame rate that you are asking for, then maybe you can not trust her, but I found her a reliable tool. It is called Perforator and is part of the WPF Performance Suite, which you can get by following the instructions here: http://msdn.microsoft.com/library/aa969767
This is probably easier than writing your own.
Also, how exactly do you request frame rates? Which API are you using? Are you using the Timeline DesiredFrameRate property? If so, it is more often used to reduce the frame rate than to increase it. (The documents also talk about increasing the frame rate to avoid tearing, but it doesnโt make much sense - tearing is caused by presenting frames from synchronization with the monitor and is not an artifact of the slow frame rate. In any case, on Vista or Windows 7, you wonโt break when DWM is enabled.) This is just a hint, and WPF does not promise to match the suggested frame rate.
As for the measurement method, you can go in several ways. If you are just trying to find out if the frame rate is in the right step, you can simply increase the counter once per frame (which you usually do in the event handler for CompositionTarget.Rendering ) and set DispatcherTimer to fire once per second and show it the value in user interface, and then reset the counter. This will be somewhat rude and ready, since DispatcherTimer not entirely accurate, but it will show you if you have 15 frames per second if you expect, for example, 30 frames per second.
If you are trying to get a more accurate look (for example, you want to try to find out if frames are constantly displayed, or from time to time you lose frames), then this gets a bit more complex. But I'll wait to see if Perforator does the trick for you before making more suggestions.
source share