UWP. UI tasks does not running when application is hidden.

Andrew Gagua 21 Reputation points
2020-01-13T13:02:15.293+00:00
auto workItemHandler = ref new WorkItemHandler( [this]( IAsyncAction^ action )
            {
                while ( action->Status == AsyncStatus::Started )
                {
                    WaitForSingleObjectEx( GetCurrentThread(), 1, FALSE );

                    if ( !processDispached )
                    {
                        processDispached = true;

                        swapChainPanel->Dispatcher->RunIdleAsync( ref new IdleDispatchedHandler( [=]( Object^ object )
                        {
                            ToDoSomething();
                            processDispached = false;
                        } ) );
                    }
                }
            } );

Hello.

I have an application with xaml. I'm creating a 'WorkItemHandler' for main application loop, but some logic processed in the ui thread.

But method 'RunIdleAsync' doesn't start when the application is hidden.

How can i fix this? And can i do this?

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,861 Reputation points
    2020-01-14T02:27:02.14+00:00

    UWP. UI tasks does not running when application is hidden.

    UWP has the specific life cycle , if the app is hidden, it will Suspended(The user either minimized or switched away from your app and didn't return to it within a few seconds.) the ui thread will stop running.

    alt text

    if you want to process some data, you could use background tasks. And you could also use extended execution.

    there are cases where an app may need to keep running, rather than be suspended, when the user navigates away from the app, or while it is minimized. For example, a step counting app needs to keep running and tracking steps even when the user navigates away to use other apps.

    For more please refer this document.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful