locked
"SuspentionManager.cs" in the model project of universal app RRS feed

  • Question

  • hi there,when the method "RestoreAsync()" be called  in app.cs,the parameter "_registeredFrames" must be empty,why the method does a foreach in "_registeredFrames",when the method called,current status must be Terminated or NotRunning,for no frames have added in it! please help me,thanks very much

            public static async Task RestoreAsync(String sessionBaseKey = null)
            {
                _sessionState = new Dictionary<String, Object>();

                try
                {
                    // Get the input stream for the SessionState file
                    StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync(sessionStateFilename);
                    using (IInputStream inStream = await file.OpenSequentialReadAsync())
                    {
                        // Deserialize the Session State
                        DataContractSerializer serializer = new DataContractSerializer(typeof(Dictionary<string, object>), _knownTypes);
                        _sessionState = (Dictionary<string, object>)serializer.ReadObject(inStream.AsStreamForRead());
                    }

                    // Restore any registered frames to their saved state
                    foreach (var weakFrameReference in _registeredFrames)
                    {
                        Frame frame;
                        if (weakFrameReference.TryGetTarget(out frame) && (string)frame.GetValue(FrameSessionBaseKeyProperty) == sessionBaseKey)
                        {
                            frame.ClearValue(FrameSessionStateProperty);
                            RestoreFrameNavigationState(frame);
                        }
                    }
                }
                catch (Exception e)
                {
                    throw new SuspensionManagerException(e);
                }
            }

    Tuesday, January 20, 2015 9:55 AM

Answers

  • before restoring the _registeredFrame list must be filled. otherwise the SuspensionManager doesnt know which frames should be restored.

    SuspensionManager isnt restoring the frames it self, but the state of the registered frames


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#


    Tuesday, January 20, 2015 10:38 AM
  • thanks dave,i got the answer,the true thing is that the previous state saved to local file,and the new frame registered can get the state by the same key
    • Marked as answer by Randolph Zhang Wednesday, January 21, 2015 3:47 AM
    Wednesday, January 21, 2015 3:47 AM

All replies

  • before restoring the _registeredFrame list must be filled. otherwise the SuspensionManager doesnt know which frames should be restored.

    SuspensionManager isnt restoring the frames it self, but the state of the registered frames


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#


    Tuesday, January 20, 2015 10:38 AM
  • thanks dave,i got the answer,the true thing is that the previous state saved to local file,and the new frame registered can get the state by the same key
    • Marked as answer by Randolph Zhang Wednesday, January 21, 2015 3:47 AM
    Wednesday, January 21, 2015 3:47 AM