public void Tick(TimerProgressState tps) { if (tps != null) { lblTime.Text = string.Format("{0}:{1}", tps.Minutes, tps.Seconds.ToString("D2")); } }
private void bgwRunTimer_ProgressChanged(object sender, ProgressChangedEventArgs e) { TimerProgressState prog = (TimerProgressState)e.UserState; if (prog != null) { ucCounterDisplay.Tick(prog); } }
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); } } }