C#控制台应用程序 - 如何使用计时器? [英] C# Console Application - How to use the timer?
问题描述
我正在制作一个非常酷的电影票订购应用程序,该应用程序使用创建的银行帐户(从我已经完成的另一个银行应用程序创建)来"付款"。为了门票。您基本上选择一部电影,选择座位,然后$ b $ b移动到购买页面,在该页面中,您可以编写一些银行帐户详细信息并订购所选电影的门票。我想添加一个可见或不可见的计时器,从您进入购买页面的确切时刻开始倒计时6分钟,所以当
到达时它会关闭应用程序。问题是,我真的不知道如何在C#中使用计时器...我怎么能这样做?
I'm working on a pretty cool cinema ticket ordering application that uses created bank accounts (which are created from another bank application I've already finished) to "pay" for the tickets. You basiclly choose a movie, choose seats and then move to the purchase page which in you write some of your bank account details and order the tickets to the chosen movie. I want to add a visible or an invisible timer that counts down 6 minutes from the exact moment you move into the purchase page, so when it arrives 0 it closes the application. The problem is, that I don't really know how to use timers in C#... How can I do this?
推荐答案
你好yuvalmus,
Hi yuvalmus,
对于迟到的回复感到抱歉。
Sorry for the late reply.
为了您的目的,请参阅这个简单的演示:
For your purpose, refer to this simple demo:
class Program
{
static int seconds = 0;
public static void Main()
{
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
aTimer.Interval = 1000;
aTimer.Enabled = true;
Console.WriteLine("Press \'q\' to quit the sample.");
while (Console.Read() != 'q') ;
}
// Specify what you want to happen when the Elapsed event is raised.
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
seconds++;
}
}
另请参阅以下类似主题:
Also please refer to the following similar thread:
问候,
Frankie
这篇关于C#控制台应用程序 - 如何使用计时器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!