locked
OnLoaded handler sub is holding up my page load RRS feed

  • Question

  • Code in my OnLoaded sub is preventing my page from displaying until it completes. Shouldn't the following code wait until the page has loaded (i.e. is visible) before running?

    Protected Sub OnLoaded() Handles Me.Loaded [code that I want to run AFTER the page is fully loaded

    - not vital to the initial display of the page] End Sub

    The code takes a couple of seconds to execute (when testing on a 1st generation RT device, which is my 'benchmark' for performance), so I want my page to navigate quickly, and then update once the OnLoaded has done its work.

    Currently when I tap the button in the previous page that page stays visible *until the code in the new page's OnLoaded finishes*, which manifests as ~2 seconds of lag. If I comment out the offending lines everything navigates quickly/as expected.

    How do I ensure some code runs only after the page is fully loaded and displayed to the user?


    I'm a self-taught noob amateur. Please take this into account when responding to my posts or when taking advice from me.

    Sunday, January 26, 2014 12:21 PM

Answers

  • Hi

    You have to move all the data fetching code to your async thread rather than your UI thread. So you can move that data processing logic into a method that returns task and then await the task inside the load method. This will allow the UI thread to be responsive.

    Regards


    Varun Ravindranath

    • Marked as answer by pumpkinszwan Monday, January 27, 2014 1:10 AM
    Sunday, January 26, 2014 7:49 PM

All replies

  • Hi

    You have to move all the data fetching code to your async thread rather than your UI thread. So you can move that data processing logic into a method that returns task and then await the task inside the load method. This will allow the UI thread to be responsive.

    Regards


    Varun Ravindranath

    • Marked as answer by pumpkinszwan Monday, January 27, 2014 1:10 AM
    Sunday, January 26, 2014 7:49 PM
  • That does work, but it doesn't make sense to me.

    My Page.Loaded event is holding up the initial display of the page when it is supposed to run *after* the page has loaded, isn't it? I don't know why my Loaded even handler was blocking the UI from updating before the page was even reached.

    Thanks for your solution. I changed my method that takes time into an async task and awaited it, and this removes the delay from the page load.


    I'm a self-taught noob amateur. Please take this into account when responding to my posts or when taking advice from me.

    Monday, January 27, 2014 1:10 AM