Windows Store App启动

时间:2012-07-19 14:56:08

标签: windows-runtime windows-store-apps launching

我的Windows Store App启动时遇到问题。当我使用“关闭应用程序手势”(从上到下滑动应用程序)然后再次快速启动应用程序时,有时会出现一个空白的黑屏,当我点击它时,会出现“开始”菜单,并且“ MoAppHang“事件被记录。

我的App_Launched事件代码在这里:

       protected override async void OnLaunched(LaunchActivatedEventArgs args)
    {
        if (args.PreviousExecutionState == ApplicationExecutionState.Terminated )
        {
            // Restore the saved session state only when appropriate
            await SuspensionManager.RestoreAsync();                
        }


        // Do not repeat app initialization when already running, just ensure that
        // the window is active
        if (args.PreviousExecutionState == ApplicationExecutionState.Running)
        {
            if (!string.IsNullOrEmpty(args.Arguments))
            {
                Frame f = Window.Current.Content as Frame;
                if (f != null)
                {
                    UseSecondaryTileNavigation(f, args.Arguments);
                }
            }
            Window.Current.Activate();
            return;
        }

        Frame rootFrame;
        if (Window.Current.Content == null)
        {

            // Create a Frame to act as the navigation context and associate it with
            // a SuspensionManager key
            rootFrame = new Frame();
            SuspensionManager.RegisterFrame(rootFrame, "AppFrame");
        }
        else
        {
            rootFrame = (Frame)Window.Current.Content;
        }

        if (!await DatabaseHelper.ExistsDatabase())
        {
            await DatabaseHelper.CreateDatabase();
        }

        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(ItemsPage), "AllGroups"))
            {
                throw new Exception("Failed to create initial page");
            }
        }

        if (!string.IsNullOrEmpty(args.Arguments))
        {
            UseSecondaryTileNavigation(rootFrame, args.Arguments);
        }

        // Place the frame in the current Window and ensure that it is active
        if (Window.Current.Content == null)
        {
            Window.Current.Content = rootFrame;
        }
        Window.Current.Activate();

当用户使用辅助磁贴打开应用时,UseSecondaryTileNavigation会执行导航(它基本上使用Frame参数并使用Frame.Navigate将其导航到正确的位置)。

我哪里错了?

谢谢大家!

1 个答案:

答案 0 :(得分:0)

看起来你可能在你的启动处理程序中做了一些耗时的工作。我提出的第一个建议是使用自定义闪屏技术。也就是说,在OnLaunched处理程序中尝试设置Window.Current.Content并激活窗口并尽快退出该方法。您可以将Window.Current.Content设置为仅显示加载进度条的页面 - 并在那里处理您的实际加载逻辑。

接下来要看的是 - 当应用程序在暂停时启动时会发生什么? (你有一个暂停处理程序吗?)你的应用程序可以处理在上一次暂停/关闭完成之前(重新)启动的情况吗?

我注意到应用程序完全关闭之前通常需要几秒钟(即使您使用向下拖动手势关闭它)。

相关问题