void WrongWay() { // this will be a deadlock, there's actually only one thread. The async methods run on the same thread! Task <Sandwich> sandwichTask = MakeBLT(); TaskAwaiter <Sandwich> awaiter = sandwichTask.GetAwaiter(); Sandwich result = awaiter.GetResult(); }
async Task PrintResult(Task <Sandwich> sandwichTask) { Sandwich sandwich = await sandwichTask; // then (sandwich) => { WriteLine($"Your {sandwich.ToString()} is done!"); } }