Answer the question
In order to leave comments, you need to log in
Why is this code blocking the UI?
Why is this code blocking the UI when it should run asynchronously?
private async void MenuOpen_Click(object sender, RoutedEventArgs e) {
Microsoft.Win32.OpenFileDialog fileDialog = new Microsoft.Win32.OpenFileDialog();
fileDialog.DefaultExt = ".txt";
fileDialog.Filter = "Text file|*.txt|All files|*.*";
fileDialog.Multiselect = false;
if (!(bool)fileDialog.ShowDialog())
return;
string content = String.Empty;
using (var file = new StreamReader(fileDialog.FileName)) {
content = await file.ReadToEndAsync();
}
tbLeft.Text = content;
}
Answer the question
In order to leave comments, you need to log in
And it's definitely not the line tbLeft.Text = content; ? Ordinary TextBoxes did not digest large amounts of text well. And this line will definitely block the UI.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question