首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何为我的Windows 8应用程序引入延迟操作

如何为我的Windows 8应用程序引入延迟操作
EN

Stack Overflow用户
提问于 2015-03-06 18:24:26
回答 1查看 47关注 0票数 0

我没有成功地在互联网上搜索我想要完成的事情(可能是因为我不知道我需要什么!)到目前为止,我已经开发了一个小游戏,有几个不同的模式和一个60秒定时器为每个问题。我剩下的唯一问题是,我不知道如何在屏幕上延迟的问题之间引入2-3秒的延迟。现在,是用户得到正确或错误的问题,下一个问题立即出现在屏幕上。我想要发生的是,屏幕变成了空白(我将用xyx.Text =“”来清除文本块;除了显示“右”的文本块!或者“错了!”持续大约3秒。

在2-3秒后,程序将继续正常,随机选择一个问题显示在屏幕上。为了清晰起见,下面是我正在使用的当前代码

代码语言:javascript
复制
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的帮助:Help with DispatcherTimer

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-06 18:55:29

示例延迟5秒:

代码语言:javascript
复制
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
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28905187

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档