我有一些虚拟软件可以在 Visual Basic 中测试秒表的精度。有人告诉我,visual basic 的时机非常好,但我遇到了一些奇怪的行为。
这是我的所有代码:
Imports System.IO
Public Class Form1
Public tmrTime As New Stopwatch
Dim currentDate As Date
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
tmrTime.Start()
End Sub
Private Sub Form1_KeyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
TextBox1.Text = (tmrTime.ElapsedTicks / Stopwatch.Frequency) * 1000
End Sub
Private Sub Form1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
TextBox2.Text = (tmrTime.ElapsedTicks / Stopwatch.Frequency) * 1000
End Sub
End Class
问题在于,如果我采用两个文本框的非小数部分(即按下的绝对时间和释放的绝对时间),它们几乎总是耦合的,即奇数或偶数。
你知道发生了什么吗?
我使用 tmrTime.ElapsedMilliseconds 或 tmrTime.Elapsed.Ticks 得到相同的结果:-\