예제 #1
0
        public static void DisplayTimeStats(MultiStopwatch clock)
        {
            //Stopwatch coffeeTook = clock.Stop("Coffee");
            //Stopwatch eggsTook = clock.Stop("Egg");
            //Stopwatch baconTook = clock.Stop("Bacon");
            //Stopwatch toastTook = clock.Stop("Toast");
            //Stopwatch juiceTook = clock.Stop("Juice");
            //Stopwatch breakfastTook = clock.Stop("Breakfast");
            //Stopwatch coffeeTook = clock.Get("Coffee");
            //Stopwatch eggsTook = clock.Get("Egg");
            //Stopwatch baconTook = clock.Get("Bacon");
            //Stopwatch toastTook = clock.Get("Toast");
            //Stopwatch juiceTook = clock.Get("Juice");
            //Stopwatch breakfastTook = clock.Get("Breakfast");

            //Console.WriteLine($"Breakfast   started at {breakfastTook.StartTime.ToString(ProcessConstants.DateTimeFormatString)} and took {breakfastTook.Seconds} seconds and {breakfastTook.Milliseconds} milliseconds.");
            //// ***
            //Console.WriteLine($"Coffee      started at {coffeeTook.StartTime.ToString(ProcessConstants.DateTimeFormatString)} and took {coffeeTook.Seconds} seconds and {coffeeTook.Milliseconds} milliseconds.");
            //Console.WriteLine($"Eggs        started at {eggsTook.StartTime.ToString(ProcessConstants.DateTimeFormatString)} and took {eggsTook.Seconds} seconds and {eggsTook.Milliseconds} milliseconds.");
            //Console.WriteLine($"Bacon       started at {baconTook.StartTime.ToString(ProcessConstants.DateTimeFormatString)} and took {baconTook.Seconds} seconds and {baconTook.Milliseconds} milliseconds.");
            //Console.WriteLine($"Toast       started at {toastTook.StartTime.ToString(ProcessConstants.DateTimeFormatString)} and took {toastTook.Seconds} seconds and {toastTook.Milliseconds} milliseconds.");
            //Console.WriteLine($"Juice       started at {juiceTook.StartTime.ToString(ProcessConstants.DateTimeFormatString)} and took {juiceTook.Seconds} seconds and {juiceTook.Milliseconds} milliseconds.");

            DisplayLineOfTimeStats("Breakfast", clock);
            // ***
            DisplayLineOfTimeStats("Coffee", clock);
            //DisplayLineOfTimeStats("Eggs", clock);
            DisplayLineOfTimeStats("Egg", "Eggs", clock);
            DisplayLineOfTimeStats("Bacon", clock);
            DisplayLineOfTimeStats("Toast", clock);
            DisplayLineOfTimeStats("Juice", clock);
        }
        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);
        }
예제 #3
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);
        }
예제 #4
0
 private static void DisplayLineOfTimeStats(string taskName, MultiStopwatch clock)
 {
     DisplayLineOfTimeStats(taskName, taskName, clock);
 }
예제 #5
0
        //private static void DisplayLineOfTimeStats(string taskName, Stopwatch taskTook)
        //private static void DisplayLineOfTimeStats(string taskName, MultiStopwatch clock)
        private static void DisplayLineOfTimeStats(string taskName, string taskDisplay, MultiStopwatch clock)
        {
            Stopwatch taskTook = clock.Get(taskName);

            //Console.WriteLine($"{taskName,11} started at {taskTook.StartTime.ToString(ProcessConstants.DateTimeFormatString)} and took {taskTook.Seconds,2} seconds and {taskTook.Milliseconds,4} milliseconds.");
            //Console.WriteLine($"{taskDisplay,11} started at {taskTook.StartTime.ToString(ProcessConstants.DateTimeFormatString)} and took {taskTook.Seconds,2} seconds and {taskTook.Milliseconds,4} milliseconds.");
            Console.WriteLine($"{taskDisplay,-11} started at {taskTook.StartTime.ToString(ProcessConstants.DateTimeFormatString)} and took {taskTook.Seconds,2} seconds and {taskTook.Milliseconds,4} milliseconds.");
        }