Home > Enterprise >  How can I use timespan to count down minutes?
How can I use timespan to count down minutes?

Time:12-23

private void TimeToDownload(Label LabelToDisplay)
{
   int _elapsedSeconds = 10;

   System.Windows.Forms.Timer _timer = new System.Windows.Forms.Timer
   {
       Interval = 1000,
       Enabled = true
   };
   _timer.Tick  = (sender, args) =>
   {
       _elapsedSeconds--;
       TimeSpan time = TimeSpan.FromMinutes(_elapsedSeconds);
       LabelToDisplay.Text = time.ToString(@"mm\:ss");
   };
}

The minutes are counting down as seconds.

09:00 then 08.00 then 07.00 the minutes count down as seconds each second one minute is down instead counting the minutes down with the seconds.

CodePudding user response:

Your TimeSpan is created FromMinutes, while it should be FromSeconds

TimeSpan.FromSeconds(_elapsedSeconds);
  • Related