Exemple #1
0
        private static async void TestCodeTaskComposition()
        {
            Stopwatch watch = new Stopwatch();

            watch.Restart();

            var taskCoffee = Task.Run(() => PourCoffee());
            var taskEggs   = Task.Run(() => FryEggs(2));
            var taskBacon  = Task.Run(() => FryBacon(3));
            var taskToast  = Task.Run(() => MakeToastWithButterAndJamAsync(2));
            var taskJuice  = Task.Run(() => PourOJ());

            Coffee cup = await taskCoffee;

            Console.WriteLine("coffee is ready");

            Egg eggs = await taskEggs;

            Console.WriteLine("eggs are ready");

            Bacon bacon = await taskBacon;

            Console.WriteLine("bacon is ready");

            Toast toast = await taskToast;

            Console.WriteLine("toast is buttered and jammy!");

            Juice oj = await taskJuice;

            Console.WriteLine("oj is ready");

            Console.WriteLine($"Task Composition Breakfast took {watch.Elapsed.TotalMilliseconds} ms to make");
            Console.WriteLine();
            Console.WriteLine();
        }
Exemple #2
0
        private static void TestCodeStandard()
        {
            Stopwatch watch = new Stopwatch();

            watch.Restart();

            Coffee cup = PourCoffee();

            Console.WriteLine("coffee is ready");

            Egg eggs = FryEggs(2);

            Console.WriteLine("eggs are ready");

            Bacon bacon = FryBacon(3);

            Console.WriteLine("bacon is ready");

            Toast toast = ToastBread(2);

            Console.WriteLine("toast is ready");

            ApplyButter(toast);
            Console.WriteLine("toast is buttered");

            ApplyJam(toast);
            Console.WriteLine("toast has been jammed!!!");

            Juice oj = PourOJ();

            Console.WriteLine("oj is ready");

            Console.WriteLine($"Standard Breakfast took {watch.Elapsed.TotalMilliseconds} ms to make");
            Console.WriteLine();
            Console.WriteLine();
        }