Example #1
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);
                    }
                }
            }
        }