I'm having a bad time with this. I'm trying to make a async method that returns the contents of a local file as string. This is my approach:
private static async Task<string> ReadContentsAsString(string fileName)
{
var uri = new Uri(string.Format(@"ms-appx:///{0}", fileName));
var file = await StorageFile.GetFileFromApplicationUriAsync(uri).AsTask().ConfigureAwait(false);
var stream = await file.OpenStreamForReadAsync().ConfigureAwait(false);
using (var streamReader = new StreamReader(stream))
{
return await streamReader.ReadToEndAsync();
}
}
Unfortunately, after the execution reaches the end of my method, the application waits forever. It hangs completely. It's being called at the very beginning, when the splash screen still shows (Windows Phone 8.1)
What do I miss?
.AsTask().ConfigureAwait(false)?