SuspensionManager Error when application has more than 1 page in windows 8 XAML/C# app

别说谁变了你拦得住时间么 提交于 2019-12-11 04:07:31

问题


I'm writing a windows 8 XAML/C# app and have a little problem with the session manager.

Within my App.xaml.cs my OnSuspending method looks like this:

    private async void OnSuspending(object sender, SuspendingEventArgs e)
    {
        var deferral = e.SuspendingOperation.GetDeferral();
        //TODO: Save application state and stop any background activity
        await SuspensionManager.SaveAsync();
        deferral.Complete();
    }

I have registed my rootFrame with the SuspensionManager in the OnLaunched method in App.xaml.cs:

SuspensionManager.RegisterFrame(rootFrame, "AppFrame");

So, in the first page of my app I have overriden the SaveState method. It looks like this:

    protected override void SaveState(Dictionary<string, object> pageState)
    {
        Save(true);

        base.SaveState(pageState);
    }

When the application is suspended this method is called and it all works fine.

I have a 2nd page with the SaveState method the same as the first (so as above).

When I navigate to the 2nd page from my 1st page and suspend the application neither of the SaveState methods are called and the application crashes with the following error:

SuspensionManager failed: Unspecified error

Brilliant!! Not much information there!!

So, do I need to do anything different with the SuspensionManager with multiple pages?

Thanks in advance


回答1:


SuspensionManager manager works with multiple pages - no issues. given the little context, i would suggest following:

  1. Have you made any changes to common files that are auto-generated when creating a vs project using grid app template? if yes - try creating a fresh project.
  2. Are you passing any parameter that is non-serializable in the frame.navigate call? it is unlikely since in that case - you can see in output window something like this - WinRT information: GetNavigationState doesn't support serialization of a parameter type which was passed to Frame.Navigate.


来源:https://stackoverflow.com/questions/15829716/suspensionmanager-error-when-application-has-more-than-1-page-in-windows-8-xaml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!