3

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

Sun
  • 4,458
  • 14
  • 66
  • 108

1 Answers1

2

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.
Sushil
  • 5,265
  • 2
  • 17
  • 15
  • Number 2 in Sushil's comment is likely to be the case. In the Build 2013 talk "Testing your C# Based Windows Store App Top 10 Areas to Look for Bugs" they specifically warn against passing non-primitives as navigation parameters, as Suspend is unable to handle them. – Jon B Aug 06 '13 at 02:02