如何为我的 Windows 8 应用引入延迟操作
How to introduce a delay in actions for my Windows 8 app
我在互联网上搜索我想要完成的事情时没有成功(可能是因为我不知道我需要什么!)。到目前为止,我已经开发了一个问答游戏,它有几种不同的模式,每个问题都有一个 60 秒的计时器。我剩下的唯一问题是,我不知道如何在屏幕上延迟的问题之间引入 2-3 秒的延迟。现在,无论用户答对还是答错,下一个问题都会立即出现在屏幕上。我想要发生的是屏幕变黑(我将使用 [xyx.Text = " ";] 清除文本块,但将显示 "Right!" 或 "Wrong!" 持续约 3 秒。
2-3 秒后,程序将正常继续,随机选择一个问题显示在屏幕上。为清楚起见,这是我当前使用的代码
public sealed partial class QuickPage : Page
{
DispatcherTimer timeLeft = new Dispatcher();
int timesTicked = 60;
public void CountDown()
{
timeLeft.Tick += timeLeft_Tick;
timeLeft.Interval = new TimeSpan(0,0,0,1);
timeLeft.Start();
}
public void timeLeft_Tick(object sender, object e)
{
lblTime.Text = timesTicked.ToString();
if (timesTicked > 0)
{
timesTicked--;
}
else
{
timeLeft.Stop();
lblTime.Text = "Times Up";
}
}
这是一个线程,我在其中获得了用于倒数计时器的 DispatcherTimer 的帮助:
延迟 5 秒的示例:
DispatcherTimer timer = new DispatcherTimer();
// Call this method after the 60 seconds countdown.
public void Start_timer()
{
timer.Tick += timer_Tick;
timer.Interval = new TimeSpan(0, 0, 5);
bool enabled = timer.IsEnabled;
// Check and show answer is correct or wrong
timer.Start();
}
void timer_Tick(object sender, object e)
{
this.Visibility = System.Windows.Visibility.Visible;
(sender as DispatcherTimer).Stop(); // Or you can just call timer.Stop() if the timer is a global variable.
// Clear screen, go to the next question
}
我在互联网上搜索我想要完成的事情时没有成功(可能是因为我不知道我需要什么!)。到目前为止,我已经开发了一个问答游戏,它有几种不同的模式,每个问题都有一个 60 秒的计时器。我剩下的唯一问题是,我不知道如何在屏幕上延迟的问题之间引入 2-3 秒的延迟。现在,无论用户答对还是答错,下一个问题都会立即出现在屏幕上。我想要发生的是屏幕变黑(我将使用 [xyx.Text = " ";] 清除文本块,但将显示 "Right!" 或 "Wrong!" 持续约 3 秒。
2-3 秒后,程序将正常继续,随机选择一个问题显示在屏幕上。为清楚起见,这是我当前使用的代码
public sealed partial class QuickPage : Page
{
DispatcherTimer timeLeft = new Dispatcher();
int timesTicked = 60;
public void CountDown()
{
timeLeft.Tick += timeLeft_Tick;
timeLeft.Interval = new TimeSpan(0,0,0,1);
timeLeft.Start();
}
public void timeLeft_Tick(object sender, object e)
{
lblTime.Text = timesTicked.ToString();
if (timesTicked > 0)
{
timesTicked--;
}
else
{
timeLeft.Stop();
lblTime.Text = "Times Up";
}
}
这是一个线程,我在其中获得了用于倒数计时器的 DispatcherTimer 的帮助:
延迟 5 秒的示例:
DispatcherTimer timer = new DispatcherTimer();
// Call this method after the 60 seconds countdown.
public void Start_timer()
{
timer.Tick += timer_Tick;
timer.Interval = new TimeSpan(0, 0, 5);
bool enabled = timer.IsEnabled;
// Check and show answer is correct or wrong
timer.Start();
}
void timer_Tick(object sender, object e)
{
this.Visibility = System.Windows.Visibility.Visible;
(sender as DispatcherTimer).Stop(); // Or you can just call timer.Stop() if the timer is a global variable.
// Clear screen, go to the next question
}