Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6976765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:32:21+00:00 2026-05-27T17:32:21+00:00

In my app (Windows 8 Metro) I store some objects in the local Folder

  • 0

In my app (Windows 8 Metro) I store some objects in the local Folder in a serialized format. Here’s the method to read then back (see below).

If I call this method with Task.Run, I can get the object:

var entity= Task.Run<Entity>(() => GetASync<Entity>(file)).Result;

but if I use the await keyword, it’s not working – on the line A (ReadObject) in the method the thread stops and exit with no error or exception:

var entity= await GetASync<Entity>(file);

Maybe I don’t use await / async as it’s recommended?

The method

private async Task<T> GetASync<T>(IStorageFile file) where T : class
{
    try
    {    
        if (file != null)
        {
            IRandomAccessStream readStream = await file.OpenAsync(FileAccessMode.Read);
            IInputStream inputStream = readStream.GetInputStreamAt(0);                   
            using (XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader(inputStream.AsStream(), XmlDictionaryReaderQuotas.Max))
            {
                DataContractSerializer serializer = new DataContractSerializer(typeof(T));
                var entity = serializer.ReadObject(reader); //line A - here the problem 
                return entity as T;
            }                    
        }
        else
        {
            return null;
        }

    }
    catch (FileNotFoundException)
    {
        return null;
    }
    catch (Exception)
    {
        throw;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:32:21+00:00Added an answer on May 27, 2026 at 5:32 pm

    Well, I have no idea why your code doesn’t work. I’m suspecting a deadlock, but there shouldn’t be one. 🙂

    However, I do have a couple performance recommendations that would probably avoid the problem as a side effect. The first is to use ConfigureAwait(false):

    IRandomAccessStream readStream = await file.OpenAsync(FileAccessMode.Read)
                                               .StartAsTask()
                                               .ConfigureAwait(false);
    

    The other is to read the file into memory (asynchronously) and then parse it. (I’m assuming from your code that you’re storing one object per file).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a small windows app, but have some trouble deciding whether to
I want to use Boost C++ in a Windows 8 Metro app and I
How should a Windows 8 Metro application connect to a central database? I've read
i have a windows app in vb.net , i am trying to read a
I'm trying to learn Windows 8 metro style app development but every time I
I have a windows app that uses SettingsProvider to read configuration settings and sets
I have just finished a metro style App in Windows Developer Preview (for the
I'm writing a metro app for Windows 8 (C# 5) to act as a
I am trying to build a Windows 8 metro-style app that will operate as
Has anyone managed to get Ninject working in Metro Style app using the Windows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.