コード例 #1
0
 public void Tick(TimerProgressState tps)
 {
     if (tps != null)
     {
         lblTime.Text = string.Format("{0}:{1}", tps.Minutes, tps.Seconds.ToString("D2"));
     }
 }
コード例 #2
0
        private void bgwRunTimer_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            TimerProgressState prog = (TimerProgressState)e.UserState;

            if (prog != null)
            {
                ucCounterDisplay.Tick(prog);
            }
        }
コード例 #3
0
        private void bgwRunTimer_DoWork(object sender, DoWorkEventArgs e)
        {
            int minutes = 0;
            int seconds = 0;

            // Get the BackgroundWorker that raised this event.
            BackgroundWorker worker = sender as BackgroundWorker;

            while (e.Cancel == false)
            {
                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                }
                else
                {
                    // Increment counters
                    seconds++;
                    if (seconds > 59)
                    {
                        minutes++;
                        seconds = 0;
                    }

                    // Update timer display
                    TimerProgressState prog = new TimerProgressState
                    {
                        Seconds = seconds,
                        Minutes = minutes
                    };
                    worker.ReportProgress(0, prog);

                    Thread.Sleep(1000);
                }
            }
        }