This is my implementation of async/await in Windows Forms Application
async Task<int> DoAysnc1() { await Task.Delay(3000); return 3000; } async Task<int> DoAsync2() { await Task.Delay(5000); return 5000; } private async void button1_Click(object sender, EventArgs e) { this.textBox1.Text = ""; var doAsync1 = DoAysnc1(); var doAsync2 = DoAysnc2(); var async1 = await doAsync1; var async2 = await doAsync2; this.textBox1.Text = $"{async1} & {async2}"; } After 5 seconds the result in the TextBox is "3000 & 5000".
But when I modify button1_Click like this:
private async void button1_Click(object sender, EventArgs e) { this.textBox1.Text = ""; var async1 = await DoAysnc1(); var async2 = await DoAysnc2(); this.textBox1.Text = $"{async1} & {async2}"; } the result is the same but it takes 8 sec.
Why second version of button1_Click act as synchronous?
DoAsync2()untilDoAsync1()is finished. Isn't that clear? There is a nice picture on msdn explaining what is happening behindasync/await, study it please.Task, it starts executing!awaitsays, when you're finished, re-enter my method here.