在我的wp8应用程序中,我有一个使用dispatchertimer的倒数计时器。我单击一个按钮并显示一个消息框当显示消息框时,倒数计时器不会继续。我希望timer_counter在显示消息框期间继续倒计时。
我试过System.Timers.Timer,但找不到类。此外,我尝试使用DispatcherPriority使计时器在后台运行。但它也找不到课程。
private DispatcherTimer timer;
private int timer_counter;
public MainPage()
{
InitializeComponent();
// set timer
timer_counter = 30; // 30 secounds
CountdownTimer.Text = new TimeSpan(0, 0, timer_counter).ToString("mm':'ss"); // show the time to textbox
timer = new DispatcherTimer();
timer.Interval = new TimeSpan(0, 0, 1); // interval: 1 second
timer.Tick += new EventHandler(dispatcherTimer_Tick);
timer.Start();
}
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
timer_counter--; // countdown
CountdownTimer.Text = new TimeSpan(0, 0, timer_counter).ToString("mm':'ss"); // show the time to textbox
}
private void Button_Click(object sender, RoutedEventArgs e)
{
MessageBoxResult result = MessageBox.Show(
"clickbutton",
"alert",
MessageBoxButton.OK);
}