C# WPF

Stopwatch 사용법

벌눈 2015. 11. 18. 11:48

Stopwatch를 사용할 때,

다음과 같이 DispatcherTimer와 Stopwatch 클래스를 사용합니다.

        using System.Windows.Threading;    // for DispatcherTimer
        using System.Diagnostics;   // for Stopwatch

        public Game()
        {
            InitializeComponent();
           
            t.Interval = new TimeSpan(0, 0, 0, 0, 100);
            t.Tick += t_Tick;
            t.Start();

            sw.Start();
           
        }

        void t_Tick(object sender, EventArgs e)
        {
            TimeSpan ts = sw.Elapsed;
            Time.Text = String.Format("Time = {0:0}:{1:00}:{2:00}.{3:00}",
                   ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
        }

 

Beeeye Dmu