예제 #1
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used when the application is launched to open a specific file, to display
        /// search results, and so forth.
        /// </summary>
        /// <param name="args">Details about the launch request and process.</param>
        protected override async void OnLaunched(LaunchActivatedEventArgs args)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();
                //Associate the frame with a SuspensionManager key                                
                SuspensionManager.RegisterFrame(rootFrame, "AppFrame");

                if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    // Restore the saved session state only when appropriate
                    try
                    {
                        //was here, but failed on resume, move to 2nd spot: await SuspensionManager.RestoreAsync();
                        await DoStartup();
                        await SuspensionManager.RestoreAsync();
                        await DoResumeFromTermination();
                    }
                    catch (SuspensionManagerException)
                    {
                        //Something went wrong restoring state.
                        //Assume there is no state and continue
                    }
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }
            if (rootFrame.Content != null)
                Window.Current.Activate(); // app is already running, or the navigation state was restored.
            else
            {
                // Code associated with DoStartup was here, now separate function, called from ExtendedStartup
                // See multimedialion.wordpress.com/2012/12/13/adding-an-extended-splash-screen-to-a-windows-8-app-tutorial-c
                SplashScreen splashScreen = args.SplashScreen;
                ExtendedSplash eSplash = new ExtendedSplash(splashScreen);
                // Register an event handler to be exectued when the splash screen has been dismissed
                splashScreen.Dismissed += new TypedEventHandler<SplashScreen, object>(eSplash.onSplashScreenDismissed);
                //Maybe not...rootFrame.Content = eSplash; // suggested by stackoverflow.com/questions/12743355/screen-flashes-between-splash-and-extended-splash-in-windows-8-app
                Window.Current.Content = eSplash;

                // Ensure the current window is active
                Window.Current.Activate();
                // THIS HUNG: Do not repeat app initialization when already running, just ensure that
                // the window is active
                //if (args.PreviousExecutionState == ApplicationExecutionState.Running)
                //{
                //    Window.Current.Activate();
                //    return;
                //}
                dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
                await DoStartup();
                Window.Current.Content = rootFrame; // restore after splash screen
                sendQueue.StartWork(); // DON'T await.  Needs to be after Window.Current.Content = rootFrame;
 //           if (rootFrame.Content == null)
 //           {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                if (!rootFrame.Navigate(typeof(HomeItemsPage), "AllGroups"))
                {
                    throw new Exception("Failed to create initial page");
                }
            }
        }
예제 #2
0
        private static void DoExtendedSplashScreen(LaunchActivatedEventArgs args)
        {
            // Code associated with DoStartup was here, now separate function, called from ExtendedStartup
            // See multimedialion.wordpress.com/2012/12/13/adding-an-extended-splash-screen-to-a-windows-8-app-tutorial-c
            SplashScreen splashScreen = args.SplashScreen;
            ExtendedSplash eSplash = new ExtendedSplash(splashScreen);
            // Register an event handler to be executed when the splash screen has been dismissed
            splashScreen.Dismissed += new TypedEventHandler<SplashScreen, object>(eSplash.onSplashScreenDismissed);
            //Maybe not...rootFrame.Content = eSplash; // suggested by stackoverflow.com/questions/12743355/screen-flashes-between-splash-and-extended-splash-in-windows-8-app
            Window.Current.Content = eSplash;

            // Ensure the current window is active
            Window.Current.Activate();
            // THIS HUNG: Do not repeat app initialization when already running, just ensure that
            // the window is active
            //if (args.PreviousExecutionState == ApplicationExecutionState.Running)
            //{
            //    Window.Current.Activate();
            //    return;
            //}
            dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
        }
예제 #3
0
 private static async Task<bool> DoExtendedSplashScreen(LaunchActivatedEventArgs args)
 {
     // Code associated with DoStartup was here, now separate function, called from ExtendedStartup
     // See multimedialion.wordpress.com/2012/12/13/adding-an-extended-splash-screen-to-a-windows-8-app-tutorial-c
     SplashScreen splashScreen = args.SplashScreen;
     ExtendedSplash eSplash = new ExtendedSplash(splashScreen);
     // Register an event handler to be executed when the splash screen has been dismissed
     splashScreen.Dismissed += new TypedEventHandler<SplashScreen, object>(eSplash.onSplashScreenDismissed);
     //Maybe not...rootFrame.Content = eSplash; // suggested by stackoverflow.com/questions/12743355/screen-flashes-between-splash-and-extended-splash-in-windows-8-app
     Window.Current.Content = eSplash;
     // Ensure the current window is active
     Window.Current.Activate();
     await DoStartup(); // This requires an active window, in order to put up (if needed) the first-run startup wizard
     bool loadState = (args.PreviousExecutionState == ApplicationExecutionState.Terminated);
     bool reloadedState = false; // until we know better
     if(loadState)
     {
         // Restore the saved session state only when appropriate
         try
         {
             await SuspensionManager.RestoreAsync();
             reloadedState = true;
         }
         catch (SuspensionManagerException)
         {
             //Something went wrong restoring state.  Assume there is no state and continue
         }
         if (reloadedState)
         {
             await DoResumeFromTermination();
             return true;
         }
     }
     return false;
 }