문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top