I'm using .Net core 3.1 and the method File.ReadAllLinesAsync blocks UI thread in wpf when awaiting it, so I took a look at the source code of this method (here) and saw that it uses async methods of StreamReader class. So I'm wondering if it is normal and if it is why ? Thanks in advance, here is my code:
private async void LoadFileButton_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog fileDialog = new OpenFileDialog()
{
Multiselect = false,
DefaultExt = "txt",
Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
};
var b = fileDialog.ShowDialog();
if (!b.HasValue || !b.Value)
return;
var l = await File.ReadAllLinesAsync(fileDialog.FileName, Encoding.UTF8);
}
edit: Well I just tried the following code :
using (var reader = File.OpenText(fileDialog.FileName))
{
l = await reader.ReadToEndAsync();
}
and it worked without blocking UI thread. So I'm starting to think if maybe the File.ReadAllLinesAsync method is broken.