Exemple #1
0
        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);
        }
Exemple #2
0
 private static void EatMeal(FinishedPastaDish finishedPastaDish, Dessert dessert)
 {
     Console.WriteLine("The pasta dish and dessert are both completed. Time to eat!");
 }