Beispiel #1
0
        static void Main(string[] args)
        {
            StopWatch clock = new StopWatch();

            clock.Start();
            clock.Start();
            System.Threading.Thread.Sleep(5000);
            clock.Stop();
            clock.Stop();
            clock.Start();
            System.Threading.Thread.Sleep(3000);
            clock.Stop();
            Console.ReadLine();
        }
Beispiel #2
0
        static void Main()
        {
            bool isRunning = true;
            var  stopWatch = new StopWatch();

            while (isRunning)
            {
                Console.WriteLine("Tap + Enter: 'y' to start, 'n' to stop, or 'q' to quit.");
                try
                {
                    switch (Console.ReadLine().ToLower())
                    {
                    case "y":
                        stopWatch.Start();
                        Console.WriteLine($"Stopwatch started at: {DateTime.Now:H:mm:ss}");
                        break;

                    case "n":
                        stopWatch.Stop();
                        Console.WriteLine($"Stopwatch stopped at: {DateTime.Now:H:mm:ss} Run time: {stopWatch.Duration}");
                        break;

                    case "q":
                        return;
                    }
                } catch (InvalidOperationException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
        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);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            StopWatch sw = new StopWatch();

            while (true)
            {
                Console.WriteLine("Press S for start, E for end: ");

                if (Console.ReadKey().Key.Equals(ConsoleKey.S))
                {
                    try
                    {
                        sw.Start();
                        Console.WriteLine("Stopwatch started!!!");
                    }
                    catch (InvalidOperationException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }

                if (Console.ReadKey().Key.Equals(ConsoleKey.E))
                {
                    try
                    {
                        sw.Stop();
                        Console.WriteLine("Stopwatch ended!!! Result:  " + sw.GetValue());
                    }
                    catch (InvalidOperationException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            StopWatch stopWatch = new StopWatch();

            while (true)
            {
                Console.WriteLine("1-start::2-stop::3-quit");

                var inputNum = Convert.ToInt32(Console.ReadLine());

                if (inputNum == 1)
                {
                    stopWatch.Start();
                }
                else if (inputNum == 2)
                {
                    stopWatch.Stop();
                    stopWatch.Calculate();
                }
                else if (inputNum == 3)
                {
                    Environment.Exit(0);
                }
                else
                {
                    throw new InvalidOperationException("Invalid input");
                }
            }
        }
        public static void Main(string[] args)
        {
            Console.WriteLine("STOPWATCH APP");
            Console.WriteLine("Press Enter to start and stop the Stop Watch!");

            var stopWatch = new StopWatch();

            while (true)
            {
                var userInput = Console.ReadLine();

                if (string.IsNullOrWhiteSpace(userInput))
                {
                    stopWatch.Start();
                    Console.ReadLine();
                    stopWatch.Stop();

                    Console.WriteLine("Duration: {0}:{1}:{2}:{3}", stopWatch.GetTime().Hours, stopWatch.GetTime().Minutes, stopWatch.GetTime().Seconds, stopWatch.GetTime().Milliseconds);

                    continue;
                }

                if (!string.IsNullOrWhiteSpace(userInput))
                {
                    Console.WriteLine("Input must be the enter key");
                    continue;
                }

                break;
            }
        }
Beispiel #7
0
        public static void Main(string[] args)
        {
            var stopWatch = new StopWatch();

            stopWatch.Start();
            stopWatch.Stop();
            Console.WriteLine("The total elapsed time is: " + stopWatch.GetDifference());
        }
Beispiel #8
0
 static void Main(string[] args)
 {
     StopWatch.Start();
     Thread.Sleep(1000 * 10);
     StopWatch.Stop();
     Thread.Sleep(1000 * 5);
     StopWatch.Reset();
     Console.Read();
 }
        static void Main(string[] args)
        {
            StopWatch.Start();
            int milliseconds = 1000;

            Thread.Sleep(milliseconds);
            StopWatch.Start();
            Thread.Sleep(milliseconds);
            StopWatch.Stop();
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            try
            {
                var watch = new StopWatch();
                watch.Start();
                Thread.Sleep(5000);
                Console.WriteLine(watch.Stop());

                watch.Start();
                Thread.Sleep(3000);

                Console.WriteLine(watch.Stop());
            }
            catch (Exception)
            {
                Console.WriteLine("Error");
            }
        }
Beispiel #11
0
        static void Main(string[] args)
        {
            var timer = new StopWatch();

            timer.Start();

            Thread.Sleep(1000);

            timer.Stop();

            Console.WriteLine("Duration: " + timer.Duration);

            timer.Start();

            for (var i = 0; i < 1000; i++)
            {
                Thread.Sleep(1);
            }

            timer.Stop();

            Console.WriteLine("Duration: " + timer.Duration);

            timer.Start();

            Thread.Sleep(1000);

            timer.Stop();

            Console.WriteLine("Duration: " + timer.Duration);
            timer.Start();

            Console.WriteLine("Press Enter to stop the timer.");
            Console.Read();

            timer.Stop();

            Console.WriteLine("Duration: " + timer.Duration);
        }
Beispiel #12
0
        static void Main(string[] args)
        {
            StopWatch.Start();
            Thread.Sleep(100);
            StopWatch.LapStop();
            Thread.Sleep(200);
            StopWatch.LapStop();

            StopWatch.Stop();
            StopWatch.DisplayAll();

            Console.ReadLine();
        }
Beispiel #13
0
        static void Main(string[] args)
        {
            try
            {
                var Stopper = new StopWatch();
                Stopper.Start();
                System.Threading.Thread.Sleep(1000);
                Stopper.Stop();
                Console.WriteLine(Stopper.Interval.Seconds);

                Stopper.Start();
                System.Threading.Thread.Sleep(1200);
                Stopper.Stop();
                Console.WriteLine(Stopper.Interval.Seconds);

                Stopper.Start();
                Stopper.Start();
            }
            catch (Exception e) {
                Console.WriteLine(e);
            }
        }
Beispiel #14
0
        static void Main(string[] args)
        {
            Console.Write("Press enter to star the timer.");
            Console.ReadLine();

            StopWatch myStopWatch = new StopWatch();
            myStopWatch.Start();

            Console.Write("Press enter to stop the timer.");
            Console.ReadLine();
            myStopWatch.Stop();

            Console.ReadLine();
        }
Beispiel #15
0
        static void Main(string[] args)
        {
            var stopwatch = new StopWatch();

            for (var i = 0; i < 2; i++)
            {
                stopwatch.Start();

                //Thread.Sleep(1000); //ritardo di 1000 millisecondi all'applicazione

                stopwatch.Stop();

                Console.WriteLine("Duration: " + stopwatch.GetTimeSpan());
                Console.ReadLine();
            }
        }
Beispiel #16
0
        static void Main(string[] args)
        {
            var stopwatch = new StopWatch();

            for (var i = 0; i < 2; i++)
            {
                stopwatch.Start();

                stopwatch.Stop(1000);

                Console.WriteLine("Duration: " + stopwatch.GetInterval());

                Console.WriteLine("Press Enter to run the stopwatch one more time");
                Console.ReadLine();
            }
        }
        public static void StopWatchInterface(string userInput, StopWatch stopWatch)
        {
            switch (userInput.ToUpper())
            {
            case "START":
                stopWatch.Start();
                break;

            case "STOP":
                stopWatch.Stop();
                break;

            default:
                break;
            }
        }
Beispiel #18
0
        static void Main(string[] args)
        {
            var stopwatch = new StopWatch();

            Console.WriteLine("Hello!");

            do
            {
                Console.WriteLine("Type 'start' to start this stopwatch: ");
                stopwatch.Start();

                Console.WriteLine("Type 'stop' to stop this stopwatch: ");
                stopwatch.Stop();

                stopwatch.DurationTime(stopwatch.StartTime, stopwatch.StopTime);
            } while (stopwatch.Command == "run");
        }
Beispiel #19
0
        static void Main(string[] args)
        {
            var stopWatch = new StopWatch();

            stopWatch.Start();

            // Do something
            for (int i = 0; i < 1000; i++)
            {
                Thread.Sleep(1);
            }
            stopWatch.Stop();

            stopWatch.Display();
            stopWatch.Reset();
            stopWatch.Display();
        }
Beispiel #20
0
        static void Main(string[] args)
        {
            var stopwatch = new StopWatch();

            for (var i = 0; i < 2; i++)
            {
                stopwatch.Start();

                Thread.Sleep(1000);

                stopwatch.Stop();

                Console.WriteLine("Duration: " + stopwatch.GetInterval().ToString());

                Console.WriteLine("Press enter to run one more time");
                Console.ReadKey();
            }
        }
Beispiel #21
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Hit enter to start Stop Watch program.");

            try
            {
                var stopwatch = new StopWatch();

                while (true)
                {
                    var input = Console.ReadLine().ToLower().Trim();
                    if (string.IsNullOrWhiteSpace(input))
                    {
                        Console.WriteLine("Enter 's' to start timer, 'q' to stop timer or '1' to quit program");
                    }
                    else if (input == "s")
                    {
                        stopwatch.Start();
                        Console.WriteLine("The timer has started.");
                        Console.WriteLine("Enter 'q' to stop or '1' to quit program.");
                    }
                    else if (input == "q")
                    {
                        stopwatch.Stop();
                        Console.WriteLine("The timer has ended.");
                        Console.WriteLine(stopwatch.Result());
                        Console.WriteLine("Enter 's' to start or 1 to quit");
                    }
                    else if (input == "1")
                    {
                        break;
                    }
                }
            }
            catch (InvalidOperationException exception)
            {
                Console.WriteLine("Error: {0}", exception.Message);
            }
            catch (Exception exception)
            {
                Console.WriteLine("Error: {0}", exception.Message);
            }
        }
        static void Main(string[] args)
        {
            StopWatch stopwatch = new StopWatch();

            stopwatch.Start();
            int[]  array = new int[20];
            Random rand  = new Random();

            for (int i = 0; i < array.Length; i++)
            {
                array[i] = rand.Next(1, 50);
                Console.Write(array[i] + " ");
            }
            selectionSort(ref array);
            Console.WriteLine("Sorted array: \n");
            printArray(ref array);
            stopwatch.Stop();
            Console.WriteLine("Time used: " + stopwatch.GetElapsedTime());
        }
        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;
            }
        }
        static void Main(string[] args)
        {
            var stopWatch = new StopWatch();

            for (var i = 0; i < 2; i++)
            {
                stopWatch.Start(DateTime.Now);

                for (var j = 0; j <= 1000; j++)
                {
                    Thread.Sleep(1);
                }

                stopWatch.Stop(DateTime.Now);

                Console.WriteLine(stopWatch.GetInterval().ToString());
                Console.ReadLine();
            }
        }
Beispiel #25
0
        static void Main(string[] args)
        {
            var stopwatch = new StopWatch();

            Console.WriteLine("This is a StopWatch application");
            Console.WriteLine("Press 'space' to start and stop, 'ESC to quit'");
            Console.WriteLine();

            while ((Console.ReadKey().Key != ConsoleKey.Escape) || (Console.ReadKey().Key == ConsoleKey.Spacebar))
            {
                if (stopwatch.MeasurementStarted == false)
                {
                    stopwatch.Start();
                }
                else
                {
                    stopwatch.Stop();
                }
            }
        }
Beispiel #26
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());
        }
        static void Main(string[] args)
        {
            var      stopWatch = new StopWatch();
            DateTime startTime;

            while (true)
            {
                Console.WriteLine("Please press \"Y\" to start the StopWatch");

                var userInput  = Console.ReadKey();
                var pressedKey = userInput.KeyChar.ToString();
                if (pressedKey == "Y")
                {
                    startTime = stopWatch.Start();
                }
                Console.WriteLine("Please Press \"N\" to stop the StopWatch");
                userInput  = Console.ReadKey();
                pressedKey = userInput.KeyChar.ToString();
                if (pressedKey == "N")
                {
                    stopWatch.Stop(startTime);
                }
            }
        }
        static void Main(string[] args)
        {
            var stopWatch = new StopWatch();

            Console.WriteLine("Welcome to Panda-Karady\'s Stop Watch");
            Console.WriteLine("Press 1 - Start, 2 - Stop, 0 - Exit");
            while (true)
            {
                var userInput = Console.ReadLine();
                var isNumber  = int.TryParse(userInput, out var value);
                if (isNumber)
                {
                    if (value == 1)
                    {
                        stopWatch.Start();
                    }
                    else if (value == 2)
                    {
                        stopWatch.Stop();
                    }
                    else if (value == 0)
                    {
                        Console.WriteLine("**********************");
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Not valid input. Try again...");
                    }
                }
                else
                {
                    Console.WriteLine("Not valid input. Try again...");
                }
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Press 1 to Start the watch\nPress 2 to stop the watch\nPress 0 to exit the program.");
            var       userInput = Convert.ToInt32(Console.ReadLine());
            StopWatch stopWatch = new StopWatch();
            bool      isStarted = false;

            while (userInput != 0)
            {
                if (userInput == 1)
                {
                    stopWatch.Start();
                    if (isStarted)
                    {
                        throw new InvalidOperationException("Stop Watch is already running");
                    }
                    isStarted = true;
                    Console.WriteLine("Started. Press 2 to Stop or 0 to exit.");
                    userInput = Convert.ToInt32(Console.ReadLine());
                }
                else if (userInput == 2)
                {
                    if (isStarted)
                    {
                        stopWatch.Stop();
                        isStarted = false;
                        Console.WriteLine("Stopped. Press 1 to Start or 0 to exit.");
                    }
                    else
                    {
                        Console.WriteLine("Start the watchor 0 to exit.");
                    }
                    userInput = Convert.ToInt32(Console.ReadLine());
                }
            }
        }