using System; using System.Threading; using System.Threading.Tasks; class Program { public static int Add(int a, int b) { Console.WriteLine("Child thread starts"); int result = a + b; Console.WriteLine("Child thread goes to sleep"); Thread.Sleep(5000); // the thread is paused for 5000 milliseconds Console.WriteLine("Child thread resumes and finishes"); return result; } public static async Task AddAsync(int a, int b) { int result = await Task.Run(() => Add(a, b)); Console.WriteLine("Result computed = {0}", result); return result; } public static void Main(string[] args) { int x = 30; int y = 12; Console.WriteLine("Main thread starts"); Task task = AddAsync(x, y); Console.WriteLine("Main thread waiting"); int sum = task.Result; Console.WriteLine("Main thread finishes, sum = {0}", sum); } }