Home > OS >  Async and await execution issue
Async and await execution issue

Time:02-27

Code Image

Why the output is like this?

123
XYZ

As per my understanding, it should print XYZ first, as I am not writing await in line no. 50

CodePudding user response:

Thread.Sleep waits synchronously. Your thread simply stops there for 10 seconds, since there's nothing telling it to go back to the caller. Try await Task.Delay(10_000) instead.

CodePudding user response:

You need set PrintDate method => public static async void and on her body set => await Test1(); because Test1 method was async

  • Related