Building a Windows 8 Metro App, Part 3: Listing 3

The RestoreAsync method in LocalStorage

static async private Task RestoreAsync()
     StorageFile sessionFile = await 

     if (sessionFile == null)

     IInputStream sessionInputStream = await sessionFile.OpenForReadAsync();

     DataContractSerializer sessionSerializer = new 
     DataContractSerializer(typeof(Dictionary<string, object>));

     _data = (Dictionary<string, object>)sessionSerializer.ReadObject(sessionInputStream.AsStream());

About the Author

Eric Vogel is a Sr. Software Developer at Kunz, Leigh, & Associates in Okemos, MI. He is the president of the Greater Lansing User Group for .NET. Eric enjoys learning about software architecture and craftsmanship, and is always looking for ways to create more robust and testable applications. Contact him at