我正在开发一个测验游戏,我想计算每个问题所需的时间。我正在考虑一个基本的解决方案,即在为用户生成问题时启动timer2,然后在用户选择答案时停止timer2,最后在标签中显示timer2 所用的时间。
但是今天我意识到在 Visual Studio 中不能使用两个以上的计时器,因为在 Visual Studio 中只能同时运行一个计时器。
顺便说一句,在我的问答游戏中,timer1 被用作倒计时器。
所以,我的问题是如何在 Visual Studio 2013 上同时运行两个计时器?
谢谢。
最佳答案
计时器是不适合这项工作的工具。也许对于整体倒计时器来说这是可以的,因为您本质上是在说“在 y 时间段后触发 x 事件”。但要测量某件事花费了多长时间,您应该使用秒表
。
// at start of the question
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
// when they select an answer
stopwatch.Stop();
// example of getting time taken
stopwatch.ElapsedMilliseconds;
PS:秒表一次不限于一个。
关于vb.net - 如何在 Visual Studio 中使用多个计时器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31874919/