秒表不以 24 小时为间隔工作,但以更短的时间间隔(如分钟)工作

Stopwatch not working with 24 hours intervals but worked with a shorter periods like minutes

秒表不以 24 小时为间隔工作,但以更短的时间间隔(如分钟)工作

Dim s1 As Stopwatch = New Stopwatch()
        s1.Start()
        'Dim starttime As String = DateTime.Now.ToString()
        While s1.Elapsed < TimeSpan.FromHours(24)
        End While

相同的代码可以正常工作 使用此方法时 TimeSpan.FromMinutes(1440) 代替 TimeSpan.FromHours(24)

基于 jmcilhinney 的评论。

    Dim s1 As Stopwatch = New Stopwatch()
    s1.Start()
    Dim ts1 As TimeSpan = TimeSpan.FromHours(24.0#)
    Dim ts2 As TimeSpan = TimeSpan.FromMinutes(24.0# * 60.0#)
    Stop 'look at ts1 and ts2.  are they the same?
    'While s1.Elapsed < ts2
    While s1.Elapsed < ts1
        Threading.Thread.Sleep(250)
    End While

展示了这一点,他的第一条评论应该引起注意。