Trying to understand async/await in the sample below:
public static Task <string> job() { Console.WriteLine("start delay 1"); Task.Delay(2000); Console.WriteLine("sleep done 1"); Task<string> t = new Task<string>(()=> { Console.WriteLine("start delay 2"); Task.Delay(3000); Console.WriteLine("sleep done 2"); return "aaaa"; }) ; t.Start(); return t; } public async static void caller() { string s = await job(); Console.WriteLine("result is {0}", s); } public static void Main() { caller(); Console.WriteLine("done with caller"); Console.ReadLine(); } To get a more clear picture I would like to make task run a bit longer and I have added Task.Delay(). Both delays are taking no time and finish immediately. Why? How to make my task spend some time on simple job to make it last longer?
awaitTask.Delay(ms)(Note you have to make job()asyncas @stuartd said for this to work)job()should also be marked asasync