none
Long running Frame.Navigate

    Question

  • Hi,

    I have a GridView control in my Win8 App populated with a list of books. The grid has a standard ItemClick event handler that navigates to another page:

    private void BookList_ItemClick(object sender, ItemClickEventArgs e)
    {
        BookViewModel book = e.ClickedItem as BookViewModel;
        if (book != null)
        {
            pageTitle.Text = "Testing..."; // just for testing
            this.Frame.Navigate(typeof(BookDetailsPage), book.ID);
        }
    }

    The BookDetailsPage happens to have a long-running operation in its OnLoad event. It should not be a problem as the OnLoad event is marked as async and the long-running call is awaited. Regardless of that, the line of code

    this.Frame.Navigate(typeof(BookDetailsPage), book.ID)

    "freezes" the UI. For example, the title of the page does not change to "Testing...". The same is when I try to show a progress ring. It does not show up.

    Why is that? How can I show an indication to the user that the next page is in the process of displaying?

    Thanks,

    Leszek


    Wiki: wbswiki.com
    Website: www.wisenheimerbrainstorm.com

    Tuesday, January 07, 2014 3:44 PM

Answers

  • You'll need to give us more information about what you're doing in OnLoad if you want more help. If you wrote it such that you have a dependency on the loaded data then that could cause an apparent freeze even if the app is technically responsive. Check that you have some basic Xaml to render before the data is ready. If the page is blank until the data is ready and bound then there won't be anything to show. If that's the case then you should be able to add a progress bar to run before waiting on your data load. Again though, with no information about what your Xaml and code look like this may not be relevant to your situation.

    Take a look at Optimize loading XAML for some general advice on loading.

    --Rob

    Wednesday, January 08, 2014 12:12 AM
    Owner

All replies

  • Does this freeze forever or does it eventually thaw out? Use the debugger to narrow down where the code is blocked so you know where to change.

    If you need more specific help we'll need more details. Can you reproduce this in a minimal test app that you can share on your SkyDrive?

    Tuesday, January 07, 2014 4:45 PM
    Owner
  • Sorry, I was not specific enough. The screen does not freeze forever. It rather pauses for a moment while the other screen retrieves data from a database.

    There is nothing special about the code. It's a standard pattern:

    1. Page A navigates to page B

    2. Page B's OnLoad event is invoked

    3. Page B's OnLoad event loads data which takes a while (the OnLoad is async and the data retrieval call is awaited)

    4. Page B is displayed.

    Thanks,

    Leszek


    Wiki: wbswiki.com
    Website: www.wisenheimerbrainstorm.com

    Tuesday, January 07, 2014 5:03 PM
  • if you go to analyse in visual studio you can do a performance test. try to do an xaml responisive test. see http://msdn.microsoft.com/en-us/library/windows/apps/dn263059(v=vs.120).aspx

    it can be very stupid things. i lately had a textblock that took over 30 seconds to layout :)


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#



    Tuesday, January 07, 2014 8:32 PM
  • Thanks Dave for your response. I have conducted some performance tests and they confirmed that the OnLoad event on the page B (the one I'm navigating to) takes time. This is what I expected. The question is not about performance - it is about responsiveness: why can't I update UI before navigating to another page? I can't change the page title (just like in the sample code I included) or show a progress ring.

    The link you gave me looked very promising. Unfortunately, the App I'm working on must support Windows 8 and the feature from the MSDN article refers to the LoggingChannel.LogMessage method which is available only on Win 8.1 :(

    Leszek


    Wiki: wbswiki.com
    Website: www.wisenheimerbrainstorm.com

    Tuesday, January 07, 2014 11:57 PM
  • You'll need to give us more information about what you're doing in OnLoad if you want more help. If you wrote it such that you have a dependency on the loaded data then that could cause an apparent freeze even if the app is technically responsive. Check that you have some basic Xaml to render before the data is ready. If the page is blank until the data is ready and bound then there won't be anything to show. If that's the case then you should be able to add a progress bar to run before waiting on your data load. Again though, with no information about what your Xaml and code look like this may not be relevant to your situation.

    Take a look at Optimize loading XAML for some general advice on loading.

    --Rob

    Wednesday, January 08, 2014 12:12 AM
    Owner