Is there a way to have a countdown timer while waiting for input?

前端 未结 1 1228
被撕碎了的回忆
被撕碎了的回忆 2021-01-16 11:46

I\'m trying to create a simple game that requires the user\'s input before the timer runs out.

Basically, the page will load with a time, and wait for the user to

相关标签:
1条回答
  • 2021-01-16 12:22
    //Add Using Statement
    using System.Windows.Threading;
    
    //Create Timer
    DispatcherTimer mytimer;
    
    //Setup Timer
    myTimer = new DispatcherTimer();
    myTimer.Interval = System.TimeSpan.FromSeconds(10);
    myTimer.Tick += myTimer_Tick;
    
    // When you type the +=, this method skeleton should come up
    // automatically. But type this in if it doesn't.
    void myTimer_Tick(object sender, EventArgs e)
    {
        //This runs when ever the timer Goes Off (In this case every 10 sec)
    }
    
    //Run Timer
    myTimer.Start()
    
    //Stop Timer
    myTimer.Stop()
    

    Does this solve your question?

    0 讨论(0)
提交回复
热议问题