public static async Task MultipleAsynchronousThreads() { Task <Dessert> prepareDessertTask = Task.Run(() => PrepareDessert()); Task <GratedCheese> grateCheeseTask = Task.Run(() => GrateCheese()); Task <BoilingWater> boilWaterTask = BoilWaterAsync(); Task <PreHeatedOven> preHeatOvenTask = PreHeatOvenAsync(); BoilingWater boilingWater = await boilWaterTask; CookedPasta cookedPasta = CookPasta(boilingWater); DrainedCookedPasta drainedCookedPasta = DrainPasta(cookedPasta); TomatoPasta tomatoPasta = AddSauceToPasta(drainedCookedPasta); GratedCheese gratedCheese = await grateCheeseTask; CheeseAndTomatoPasta cheeseAndTomatoPasta = AddCheeseToPasta(gratedCheese, tomatoPasta); PreHeatedOven preHeatedOven = await preHeatOvenTask; FinishedPastaDish finishedPastaDish = await BakePastaAsync(cheeseAndTomatoPasta, preHeatedOven); Dessert dessert = await prepareDessertTask; EatMeal(finishedPastaDish, dessert); }
private static void EatMeal(FinishedPastaDish finishedPastaDish, Dessert dessert) { Console.WriteLine("The pasta dish and dessert are both completed. Time to eat!"); }