I just wantend to know if there is a possibility to deserialize data from file NOT asynchronously in WinRT application. It looks like I have to get StorageFile object to deserialize it and getting it must be async. Is that right? Or maybe you know if I can do it synchronously? This the the async code that works, but it is ASYNC
public static async Task<StorageFile> GetFileFromAsync(string relativeFileName)
{
StorageFolder localAppDataFolder = ApplicationData.Current.LocalFolder;
try
{
StorageFile file = await localAppDataFolder.GetFileAsync(relativeFileName);
return file;
}
catch (FileNotFoundException)
{
return null;
}
}
public static async Task<T> ReadFromXmlInIsAsync<T>(string path) where T : class
{
T data;
StorageFile isolatedStorageFile = await IsolatedStorageHelper.GetFileFromAsync(path);
if(isolatedStorageFile == null) return null;
using (IInputStream sessionInputStream = await isolatedStorageFile.OpenReadAsync())
{
DataContractSerializer sessionSerializer = new DataContractSerializer(typeof(T));
data = (T)sessionSerializer.ReadObject(sessionInputStream.AsStreamForRead());
}
return data;
}
No, there is not a way to do it synchronously.
All WinRT APIs are asynchronous to encourage developers to write responsive applications.