Example #1
0
        static void Main(string[] args)
        {
            var stopWatch = new StopWatch();
            int choice;

            do
            {
                Console.Write("Choose operation :\n 1 - Start the measurement\n 2 - Finish the measurement\n 3 - Result of measurement\n 0 - Close the program\n");
                choice = Convert.ToInt32(Console.ReadLine());

                switch (choice)
                {
                case 1:
                    stopWatch.Start();
                    break;

                case 2:
                    stopWatch.Stop();
                    break;

                case 3:
                    Console.WriteLine("The duration of the measurement is : " + stopWatch.Duration());
                    break;
                }
                if (choice == 0 || choice == 1 || choice == 2 || choice == 3)
                {
                }
                else
                {
                    Console.WriteLine("The wrong choice was made!");
                }
            } while (choice != 0);
        }
        static void Main(string[] args)
        {
            var stopWatch = new StopWatch();

            Console.WriteLine("Press Enter to start StopWatch or Exit");
            while (true)
            {
                var input = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(input))
                {
                    stopWatch.Start();
                    Console.ReadLine();
                    stopWatch.Stop();
                    Console.WriteLine(stopWatch.Duration());
                    continue;
                }
                break;
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            var startTime = StopWatch.Start();

            System.Console.WriteLine("Start Time : " + startTime);

            Thread.Sleep(60000);
            var endTime = StopWatch.Stop();

            System.Console.WriteLine("End Time : " + endTime);
            Console.WriteLine(StopWatch.Duration());

            startTime = StopWatch.Start();

            System.Console.WriteLine("Start Time : " + startTime);

            Thread.Sleep(60000);
            endTime = StopWatch.Stop();

            System.Console.WriteLine("End Time : " + endTime);
            Console.WriteLine(StopWatch.Duration());
        }