Monday, 15 March 2010

rendering - WPF determine optimal UI update rate -



rendering - WPF determine optimal UI update rate -

is there way in wpf determine optimal ui update rate, that

no frames skipped and ui stays responsible.

it not create sense to lot work notify ui values have changed when render process not able maintain pace. indeed, notice when seek update often, ui gets unresponsive , little fraction of frames displayed (e.g. invalidatevisual() called 10 times, 1 new frame displayed). instead, prefer ui updated @ native rendering rate.

up now, tried dispatchertimer, if cut down priority background, update method called more rendering occurs (frames skipped) if update rate high. rate depends on hardware , number of elements on screen. if farther cut down priority, timer not called @ (perhaps there background thread running update values).

alex

i wrote quick test see frame rate i'm getting in test .net wpf app.

i'm seeing rate of between 60-63 frames per second, monitor refresh rate 60 hz, guess i'm seeing ui updating @ native rate.

i wrote using compositiontarget.rendering event , implemented behavior , attached textblock in simple mvvm style app:

xaml:

<textblock> <i:interaction.behaviors> <views:frameratebehavior /> </i:interaction.behaviors> </textblock>

c# code:

public sealed class frameratebehavior : behavior<textblock> { private readonly queue<long> _ticks = new queue<long>(); public frameratebehavior() { _ticks = new queue<long>(); } protected override void onattached() { base.onattached(); compositiontarget.rendering += calculateframerate; } protected override void ondetaching() { base.ondetaching(); compositiontarget.rendering -= calculateframerate; _ticks.clear(); } private void calculateframerate(object sender, eventargs e) { var = datetime.now; var endtime = now.ticks; var starttime = now.addseconds(-1).ticks; while (_ticks.any()) { if (_ticks.peek() < starttime) { _ticks.dequeue(); continue; } break; } _ticks.enqueue(endtime); var count = _ticks.count; associatedobject.text = "fps: " + count; } }

wpf rendering frame-rate

No comments:

Post a Comment