I am trying to learn asynchronous programming (C#/WPF) and I cant seem to understand some things, so I started with a simpler example but I am still stuck.
Example: Adds 2 lines of texts to a textbox, and shows the time it took, on the event of a button press.
This is the code:
private async void b1_Click(object sender, RoutedEventArgs e)
{
txtb1.Text = "";
var watch = System.Diagnostics.Stopwatch.StartNew();
await writeintxtbx();
watch.Stop();
var elapsedtm = watch.ElapsedMilliseconds;
txtb1.Text += $"TOTAL TIME {elapsedtm} \n\n\n";
}
private async Task writeintxtbx()
{
await Task.Run(() => Task1());
await Task.Run(() => Task2());
}
private void Task1()
{
txtb1.Text += $"Task 01 Done \n\n";
}
private void Task2()
{
txtb1.Text += $"Task 2 done \n\n";
}
This is the error I am getting:
]]1