我在启动 Windows 应用商店应用时遇到问题。当我使用“关闭应用程序手势”(从上到下滑动应用程序)然后非常快速地再次启动应用程序时,有时会出现一个空白黑屏,当我单击它时,会出现开始菜单,并出现“ 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 将其导航到正确的位置)。
我哪里错了?
谢谢你们!