I am trying to do a simple countdown timer from 1 minute, that is shown in the button text. When the button is pressed I just want it to count down to 0, the show “times up”. I have been reading all the posts I can find trying to figure out how to do this and cannot. Can someone tell me what I am doing wrong.
This is in in visual c# windows phone application. I hope I made the post appear correctly, this is my first time to ask a question on this site, I am new to this. Thank you in advance for any advice.
void bTime_Click(object sender, RoutedEventArgs e)
{
DispatcherTimer timer1 = new DispatcherTimer();
timer1.Interval = TimeSpan.FromSeconds(60);
timer1.Tick += new EventHandler(timer_Tick);
timer1.Start();
}
int tik = 60;
void timer_Tick(object sender, EventArgs e)
{
bTime.Content = timer.ToString();
if (tik > 0)
Countdown.Text = (timer--).ToString();
else
Countdown.Text = "Times Up";
throw new NotImplementedException();
}
First, get rid of
throw new NotImplementedException. Second, you need to decrement tik. So something like this:I have changed Interval and i’m decrementing tik every second. Nice and simple. Hope it helps. Let me know if you don’t understand.