skip to Main Content

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

2

Answers


  1. 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.

    Login or Signup to reply.
  2. You need set PrintDate method => public static async void and on her body set => await Test1(); because Test1 method was async

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search