Hallo,
ich verstehe nicht, warum der UI-Thread blockiert. Kann mir das jemand erklären?
#region Async
private async void cmdProgrammLaden_Click(object sender, EventArgs e)
{
Console.WriteLine("Button-Thread-ID: " + Thread.CurrentThread.ManagedThreadId);
this.txtSendData.Text = await DncProgrammLadenAsync();
}
async Task<string> DncProgrammLadenAsync()
{
string path = String.Empty;
string content = String.Empty;
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.InitialDirectory = @"c:\Test\";
openFileDialog.Filter = "Textdateien (*.txt)|*.txt";
openFileDialog.FilterIndex = 2;
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog()==DialogResult.OK)
{
path = openFileDialog.FileName;
var filestream = openFileDialog.OpenFile();
using (StreamReader reader = new StreamReader(filestream))
{
Console.WriteLine("Task-Thread-ID: "+Thread.CurrentThread.ManagedThreadId);
content = await reader.ReadToEndAsync();
//Thread.Sleep(3000);
}
}
return content;
}
}
#endregion Async
Ich bin im .NET-Framework unterwegs (4.7.2)
Grüße
|