public static async Task MakeBreakfastAsync()
        {
            MultiStopwatch clock = new MultiStopwatch();


            clock.Start("Breakfast");
            // ***


            clock.Start("Coffee");
            // ***
            Coffee cup = PourCoffee();

            Console.WriteLine("coffee is ready");
            // ***
            clock.Stop("Coffee");


            //clock.Start("Egg");
            //// ***
            //Task<Egg> eggsTask = FryEggsAsync(2);


            //Egg eggs = await eggsTask;
            //Console.WriteLine("eggs are ready");
            //// ***
            //clock.Stop("Egg");


            //clock.Start("Bacon");
            //// ***
            //Task<Bacon> baconTask = FryBaconAsync(3);


            //Bacon bacon = await baconTask;
            //Console.WriteLine("bacon is ready");
            //// ***
            //clock.Stop("Bacon");


            clock.Start("Toast");
            // ***
            //Task<Toast> toastTask = ToastBreadAsync(2);
            Task <Toast> toastTask = MakeToastWithButterAndJamAsync(2);


            //Egg eggs = await eggsTask;
            //Console.WriteLine("eggs are ready");
            //// ***
            //clock.Stop("Egg");


            //Bacon bacon = await baconTask;
            //Console.WriteLine("bacon is ready");
            //// ***
            //clock.Stop("Bacon");


            Toast toast = await toastTask;

            //ApplyButter(toast);
            //ApplyJam(toast);
            Console.WriteLine("toast is ready");
            // ***
            clock.Stop("Toast");


            //IList<Task> breakfastTasks = new List<Task> { eggsTask, baconTask, toastTask };
            //while (breakfastTasks.Count > 0)
            //{
            //    Task finishedTask = await Task.WhenAny(breakfastTasks);
            //    if (finishedTask == eggsTask)
            //    {
            //        Console.WriteLine("eggs are ready");
            //        // ***
            //        clock.Stop("Egg");
            //    }
            //    else if (finishedTask == baconTask)
            //    {
            //        Console.WriteLine("bacon is ready");
            //        // ***
            //        clock.Stop("Bacon");
            //    }
            //    else if (finishedTask == toastTask)
            //    {
            //        //ApplyButter(toast);
            //        //ApplyJam(toast);
            //        Console.WriteLine("toast is ready");
            //        // ***
            //        clock.Stop("Toast");
            //    }
            //    breakfastTasks.Remove(finishedTask);
            //}


            clock.Start("Juice");
            // ***
            Juice oj = PourOJ();

            Console.WriteLine("oj is ready");
            // ***
            clock.Stop("Juice");


            clock.Start("Egg");
            // ***
            Task <Egg> eggsTask = FryEggsAsync(2);


            clock.Start("Bacon");
            // ***
            Task <Bacon> baconTask = FryBaconAsync(3);


            Egg eggs = await eggsTask;

            Console.WriteLine("eggs are ready");
            // ***
            clock.Stop("Egg");


            Bacon bacon = await baconTask;

            Console.WriteLine("bacon is ready");
            // ***
            clock.Stop("Bacon");


            Console.WriteLine("Breakfast is ready!");
            // ***
            clock.Stop("Breakfast");


            ProcessHelpers.DisplayTimeStats(clock);
        }
Esempio n. 2
0
        public static void MakeBreakfast()
        {
            MultiStopwatch clock = new MultiStopwatch();

            clock.Start("Breakfast");
            // ***


            clock.Start("Coffee");
            // ***
            Coffee cup = PourCoffee();

            Console.WriteLine("coffee is ready");
            // ***
            clock.Stop("Coffee");


            clock.Start("Egg");
            // ***
            Egg eggs = FryEggs(2);

            Console.WriteLine("eggs are ready");
            // ***
            clock.Stop("Egg");


            clock.Start("Bacon");
            // ***
            Bacon bacon = FryBacon(3);

            Console.WriteLine("bacon is ready");
            // ***
            clock.Stop("Bacon");


            clock.Start("Toast");
            // ***
            Toast toast = ToastBread(2);

            ApplyButter(toast);
            ApplyJam(toast);
            Console.WriteLine("toast is ready");
            // ***
            clock.Stop("Toast");


            clock.Start("Juice");
            // ***
            Juice oj = PourOJ();

            Console.WriteLine("oj is ready");
            // ***
            clock.Stop("Juice");


            Console.WriteLine("Breakfast is ready!");
            // ***
            clock.Stop("Breakfast");

            ProcessHelpers.DisplayTimeStats(clock);
        }