Can someone please explain me the difference between those two blocks.
This one executes about 2 seconds (that means that awaits are asynchronous.):
[Test] public async void TestAwait() { var sw = new Stopwatch(); sw.Start(); var task = TestAwaiter(5, 2000).ConfigureAwait(false); var task1 = TestAwaiter(10, 2000).ConfigureAwait(false); var i = await task; var j = await task1; Console.WriteLine(i+j); Console.WriteLine(Math.Round(sw.Elapsed.TotalSeconds, 0)); Assert.AreEqual(Math.Round(sw.Elapsed.TotalSeconds, 0), 2); sw.Stop(); } public async Task<int> TestAwaiter(int num, int waitTimeSec) { await Task.Delay(waitTimeSec).ConfigureAwait(false); return num; } This one executes about 4 seconds (that means that awaits are synchronous.)
[Test] public async void TestAwait() { var sw = new Stopwatch(); sw.Start(); var i = await TestAwaiter(5, 2000).ConfigureAwait(false); var j = await TestAwaiter(10, 2000).ConfigureAwait(false); Console.WriteLine(i+j); Console.WriteLine(Math.Round(sw.Elapsed.TotalSeconds, 0)); Assert.AreEqual(Math.Round(sw.Elapsed.TotalSeconds, 0), 2); sw.Stop(); } public async Task<int> TestAwaiter(int num, int waitTimeSec) { await Task.Delay(waitTimeSec).ConfigureAwait(false); return num; } I can't understand how they are different. Why assigning the await for task later then creating it affects the execution order.
async void?