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
).async
all the way down; don't block on async
code.In your case, it sounds like Load
may be called as part of startup. This is a bit tricky to do asynchronously (since constructors may not be async
). However, you should be able to get it to work by utilizing asynchronous lazy initialization.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With