locked
Extended splashscreen and threading

    Question

  • Hello,

    I'm trying to apply the Extended Splash Screen tutorial to my universal app. However, it does not work as expected. Granted, I had to modify the code slightly to integrate it to my existing app (and obviously I made some mistakes...). But I still don't fully understand what is causing the issue.

    Basically, I am able to see/display the extended splash screen after the normal one. However, an error occurs in my "DismissedEventHandler" (called after the dismissal of the normal splash screen). In this Handler, I am loading all the background stuff that my app needs to load at startup. And then I am trying to navigate back to the home page. This is where the error occurs. I cannot either change Window.Current.Content or Frame.Navigate, because both are null.

    My understanding after some web search is that the dismissed event Handler is occuring on a different thread than the main UI. Therefore I cannot navigate from there. In the tutorial they are using a UI button click Handler to navigate from the extended splash screen to the home page. But how can I do it without user input?

    There is a comment in the tutorial saying "ExtendedSplash.xaml includes a DismissSplash button. When this button is clicked, an event handler, DismissSplashButton_Click, calls the DismissExtendedSplash method. In your app, call DismissExtendedSplash when your app is done loading resources or initializing its UI."

    Which UI/app event can I use to know that all the background loading is finished and navigate to the home page?

    Thanks & Kind Regards,

    Mathieu

    Monday, August 4, 2014 8:11 PM

Answers

  • OK sorry, just figured out I had to do:

    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
    {

    Frame rootframe = Window.Current.Content as Frame;

    rootframe.Navigate(typeof(Home));
    });

    Still looks a bit strange to me having to explicitly "navigate" between threads like that.

    Sunday, August 10, 2014 11:29 AM

All replies

  • You can use Dispatcher.RunAsync to marshal a delegate onto the UI thread from your worker thread. Once there it should be able to dismiss the splash screen.

    --Rob

    Monday, August 4, 2014 11:39 PM
    Owner
  • Hello,

    Thank you for the suggestion. From my handler in the worker thread, I have tried the following ("Home" is the class name of my main page):

    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
    {
       Frame.Navigate(typeof(Home));
    });

    However, the debugger breaks on the "Frame.Navigate" call because "Frame" is null. It seems at this point I am still in a worker thread and not the UI main thread. I suspect I'm not applying correctly your suggestion. I'm not very familiar with the threading concept. It's the first time I really have to deal with this explicitly. Could you give a more detailed example?

    Is this the only way of dealing with an extended splash screen? This looks very complex to me and I'm surprised the tutorial on MSDN does not detail the last part, i.e. how to go back to the main page. Is there really no event on the main UI thread I could use for this purpose?

    Thanks again for your support.

    Sunday, August 10, 2014 11:18 AM
  • OK sorry, just figured out I had to do:

    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
    {

    Frame rootframe = Window.Current.Content as Frame;

    rootframe.Navigate(typeof(Home));
    });

    Still looks a bit strange to me having to explicitly "navigate" between threads like that.

    Sunday, August 10, 2014 11:29 AM