0

When using async Methods of PCLStorage there is a strange behaviour on UWP.

In the Constructor of App I have to load a json file by PCLStorage. The first file Operation is a CheckFileAsync. As the App constructor is not an async method (it's ok if it blocks for a moment) I first tried this:

var catalogue =FreshTinyIOCBuiltIn.Current.Resolve<IStorageManager>().GetCatalogue(null).Result;

Which works fine on Android. But on UWP it blocks completely and never comes back.

If I do it this way:

Catalogue catalogue = null;
var t = Task.Run(async () =>
{
    catalogue = await FreshTinyIOCBuiltIn.Current.Resolve<IStorageManager>().GetCatalogue(null);
});
t.Wait();

Everything is fine. What is the reason for this?

Dimitri
  • 8,122
  • 19
  • 71
  • 128
Thomas
  • 8,397
  • 7
  • 29
  • 39
  • 1
    Are you sure that this is not SynchronizationContext issue as in this SO question https://stackoverflow.com/questions/10343632/httpclient-getasync-never-returns-when-using-await-async I know the question above is an example of ASP.Net deadlock but it sounds very similar – InitLipton Mar 15 '16 at 11:28
  • This could be. The only thing, what I don't understand is, why it works under Android. I will try if ConfigureWait(false) solves the problem. – Thomas Mar 15 '16 at 13:33
  • I tried to use ConfigureWait(false) but how do I use it in a non async method where I can't use await? – Thomas Mar 15 '16 at 15:50

0 Answers0