I am following the wait for the MSDN tutorial, and I am trying to figure out the difference between using awaitas instead of using awaitas an expression. All this asynchronous expected thing bends my mind, and I can not find examples for this particular case.
Basically, I wanted to see how to use multiple asynchronously await, which means that I don't want to wait for the first to complete before the second starts. This, for me, hits the goal of asynchrony:
private async void button1_Click(object sender, EventArgs e)
{
string result_a = await WaitAsynchronouslyAsync();
string result_b = await WaitAsynchronouslyAsync();
textBox1.Text = result_a + Environment.NewLine;
textBox1.Text += result_b;
}
public async Task<string> WaitAsynchronouslyAsync()
{
await Task.Delay(3000);
return "Finished";
}
However, with a subtle change, it takes only 3 seconds to display two "Ready", what I want - two awaitwork really asynchronously:
private async void button1_Click(object sender, EventArgs e)
{
var a = WaitAsynchronouslyAsync();
var b = WaitAsynchronouslyAsync();
await a;
await b;
textBox1.Text = a.Result + Environment.NewLine;
textBox1.Text += b.Result;
}
My question is: why do they behave differently? What thin point do I not see here?