Answered by:

Show progress ring during rendering process

Question

I'm trying to show a progress ring during the rendering, because this may take several seconds. The app doesn't respond in that time, so i tried to set the activity of the progress ring defined in the xaml markup to true at the beginning of the OnRendering-method
(defined in the Direct2D + Xaml template which i'm using) and set it to false at the end, but the app doesn't show any response. When the ring is only activated, it becomes active immediately at the beginning. What am i doing wrong? Furthermore the app-requirements
say that a progress ring should only be shown when the latency is 500ms or more. How is that realisable ? Any suggestions on howto solve my problem were helpful. Thanx!

Your calls to m_renderer->Update, m_renderer->Render, and m_renderer->Present all run on the UI thread. As a result you are tying up the UI thread, preventing anything else (such as the XAML progress ring) from being displayed or updated until your
m_renderer calls complete.

If you have some long running rendering code, you'll need to figure out a way to break up the tasks into shorter bits that can be done over the course of several calls to OnRendering or else you'll need to carefully design your code such that you can run
the long running parts on a background thread and only when those are done come back and perform the actual rendering on the UI thread. The second option assumes that what's taking long isn't the rendering itself but is just some preparation for the drawing.

There is no boilerplate answer since it's a (potentially) complex design and code structure question that depends very much on the specific details of what you are trying to do.

Await won't do any good since this is C++, not C# or VB. But you might want to investigate async programming using the parallel patterns library (PPL). The Hilo project from the patterns & practices team is really helpful for understanding PPL tasks
and C++ async programming in Windows Store apps:
http://msdn.microsoft.com/en-us/library/windows/apps/jj160321.aspx .

Your calls to m_renderer->Update, m_renderer->Render, and m_renderer->Present all run on the UI thread. As a result you are tying up the UI thread, preventing anything else (such as the XAML progress ring) from being displayed or updated until your
m_renderer calls complete.

If you have some long running rendering code, you'll need to figure out a way to break up the tasks into shorter bits that can be done over the course of several calls to OnRendering or else you'll need to carefully design your code such that you can run
the long running parts on a background thread and only when those are done come back and perform the actual rendering on the UI thread. The second option assumes that what's taking long isn't the rendering itself but is just some preparation for the drawing.

There is no boilerplate answer since it's a (potentially) complex design and code structure question that depends very much on the specific details of what you are trying to do.

Await won't do any good since this is C++, not C# or VB. But you might want to investigate async programming using the parallel patterns library (PPL). The Hilo project from the patterns & practices team is really helpful for understanding PPL tasks
and C++ async programming in Windows Store apps:
http://msdn.microsoft.com/en-us/library/windows/apps/jj160321.aspx .