var func = GetInstance(); // Delegate has not started executing yet var task = func(); // Delegate has started executing var result = await task; // Delegate is done
class Program { public static void Main(string[] args) { // Only RUN the task as needed. FooGet // still allows you to generalize your task. Task.Run(() => { dynamic value = FooGet(); value.RunSynchronously(); Console.WriteLine(value.Result.Result.ToString()); }); while (true) Thread.Sleep(100); } private static Task FooGet() { var task = new Task(() => { return asyncBar(); }); return task; } private async static Task asyncBar() { // do work! return "Hello, world!"; } }