如何在Visual Studio中使用多个计时器?

时间:2015-08-07 09:57:41

标签: vb.net visual-studio-2013 vbscript timer

我正在开展测验游戏,我想计算每个问题的时间。我正在考虑一个基本的解决方案,即在为用户生成问题时启动timer2,然后在用户选择答案时停止timer2,然后最终显示timer2在标签中经过的时间。

但是今天我意识到你不能在Visual Studio中使用两个以上的计时器,因为在Visual Studio中只能同时运行一个计时器。

顺便说一句,在我的测验游戏中,timer1用作倒数计时器。

所以,我的问题是如何在Visual Studio 2013上同时运行两个计时器?

感谢。

enter image description here

1 个答案:

答案 0 :(得分:2)

计时器是该作业的错误工具。也许对于整体倒数计时器来说,这是可以的,因为你基本上是说"在y时间段之后触发x事件"。但是,为了衡量某些事情需要多长时间,您应该使用Stopwatch

// 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:秒表不限于一次。

相关问题