Possible Duplicate:
WinRT: Loading static data with GetFileFromApplicationUriAsync()
The following code in my application is called, but it never returns, or throws an exception:
public async Task Load()
{
...
StorageFile file =
await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///" + name));
...
}
This is how I call the method:
x.Load().Wait();
Why does the awaited method GetFileFromApplicationUriAsync() never return?
When you (synchronously) block on asynchronous code, you run into a deadlock problem.
Follow these best practices:
ConfigureAwait(false)whenever possible in your library methods (e.g.,Load).asyncall the way down; don’t block onasynccode.In your case, it sounds like
Loadmay be called as part of startup. This is a bit tricky to do asynchronously (since constructors may not beasync). However, you should be able to get it to work by utilizing asynchronous lazy initialization.