How to achieve smooth UI updates every 16 ms?

前端 未结 3 437
滥情空心
滥情空心 2021-01-12 11:39

I am trying to create sort of a radar. Radar is VisualCollection that consists of 360 DrawingVisual\'s (which represent radar beams). Radar is placed on Viewbox.

<         


        
相关标签:
3条回答
  • 2021-01-12 12:18

    For smooth WPF animations you should make use of the CompositionTarget.Rendering event.

    No need for a thread or messing with the dispatcher. The event will automatically be fired before each new frame, similar to HTML's requestAnimationFrame().

    In the event update your WPF scene and you're done!

    There is a complete example available on MSDN.

    0 讨论(0)
  • 2021-01-12 12:25
    while (Environment.TickCount - beginTime < delay) { }
            delay += deltaDelay;
    

    The sequence above blocks the thread. Use instead "await Task.Delay(...)" which doesn't block the thread like its counterpart Thread.Sleep(...).

    0 讨论(0)
  • 2021-01-12 12:27

    You can check some graphics bottleneck using the WPF Performance Suite:

    http://msdn.microsoft.com/es-es/library/aa969767(v=vs.110).aspx

    Perforator is the tool that will show you performance issues. Maybe you are using a low performance VGA card?

    0 讨论(0)
提交回复
热议问题