Home > Mobile >  .NET asnyc and await execution issue
.NET asnyc and await execution issue

Time:02-27

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

Code Image

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