Esempio n. 1
0
        static void Main(string[] args)
        {
            var stopwatch = new StopWatch();

            stopwatch.Start();
            for (var i = 0; i < 2; i++)
            {
                Thread.Sleep(1);
            }
            stopwatch.End();
            Console.WriteLine("TimeSapn : {0}", stopwatch.GetTimeSpan());
        }
Esempio n. 2
0
        public void StopWatch()
        {
            StopWatch stopwatch = new StopWatch();

            stopwatch.Start();
            TemporalHelpers.PauseExecution(2000);
            stopwatch.Stop();

            Assert.AreEqual(2, stopwatch.GetSeconds <int>(), "GetSeconds()");

            stopwatch.StopDate = stopwatch.StartDate.AddSeconds(1);
            Assert.AreEqual("00:00:01", stopwatch.GetTimeSpan().ToString(@"hh\:mm\:ss"), "GetTimeSpan() 1 second");

            stopwatch.StopDate = stopwatch.StartDate.AddDays(1);
            Assert.AreEqual("1.00:00:00", stopwatch.GetTimeSpan().ToString(@"d\.hh\:mm\:ss"), "GetTimeSpan() 1 day");

            stopwatch.StopDate = stopwatch.StartDate.AddDays(3).AddHours(5).AddMinutes(7).AddSeconds(15);
            Assert.AreEqual("3.05:07:15", stopwatch.GetTimeSpan().ToString(@"d\.hh\:mm\:ss"), "GetTimeSpan() complex");

            stopwatch.StopDate = stopwatch.StartDate.AddDays(3).AddHours(5).AddMinutes(7).AddSeconds(15).AddMilliseconds(999);
            Assert.AreEqual("3.05:07:15.999", stopwatch.GetTimeSpan().ToString(@"d\.hh\:mm\:ss\.fff"), "GetTimeSpan() complex 2");
        }