WPF blocking attempt asynchronously

I am learning about async / await keywords. I can't see what I am doing here syntactically here?

I have the following two methods:

private async Task<string> PopupAsync()
{
  String result;
  using (StreamReader reader = File.OpenText(@"C:\temp\JBM_SchedulingModule.xap"))
  {
    Console.WriteLine("Opened file.");
    txtData.Text = "Opened file.";
    result = await reader.ReadToEndAsync();

  }
  return result;
}

      

and

private async void Button_Click(object sender, RoutedEventArgs e)
{
  txtData.Text = await PopupAsync();
}

      

The main UI thread freezes when I click the button and I don't want that. Trying to understand why and how to fix it.

Thank!

0


source to share


1 answer


Stephen is right. I understood. He works as he was supposed to. The reason it was blocking was not because of ReadToEndAsync (), but the time it took to fill + load the 4MB line (from file) into the WPF control.



0


source







All Articles