0

我有一个间隔 = 1 的计时器

间隔 1 = 1 毫秒?

如果间隔 1 不是 1 毫秒,
那么告诉我哪个控制间隔 = 1 毫秒

代码:

Imports System.Globalization

Public Class Form1
    'Default Time To Start From
    Dim time As String = "00:00:00,000" 'Start From Here

    'Label
    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
        Timer1.Start() 'Run The Timer On Click
    End Sub

    'TIMER
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        'Timer Interval = 1

        Dim ci = CultureInfo.InvariantCulture

        Dim original As TimeSpan = TimeSpan.ParseExact(time, "hh\:mm\:ss\,fff", ci) 'ParseExact

        Dim difference As TimeSpan = TimeSpan.FromMilliseconds(1) ' = 1  Millisecond

        Dim final = original

        final = original + difference ' connect between original to difference !(00:00:00,000 + 1 MS = 00:00:00,001)!

        Dim output As String = final.ToString("hh\:mm\:ss\,fff", ci) 'convert to the format (  = 00:00:00,001  ) (Back It To The Right Format)

        time = output '!!Update!! the Time String from 00:00:00,000 To 00:00:00,001 |||| And in the Next Time 00:00:00,001 + 1 = 00:00:00,002

        Label1.Text = time 'Show the Time String in the label

    End Sub

End Class

如您所见-我使用间隔为 1 的常规计时器
,但我认为它已磨损,因为

如果您有建议,计时器不计算毫秒,请告诉我。

4

2 回答 2

1

来自 MSDN 的区间属性的描述是:

获取或设置在引发 Tick 事件之前相对于最后一次发生 Tick 事件的时间(以毫秒为单位)。

然而(正如史蒂夫在他的评论中指出的那样):

Windows 窗体计时器组件是单线程的,精度限制为 55 毫秒。如果您需要更准确的多线程计时器,请使用 System.Timers 命名空间中的 Timer 类

取自http://msdn.microsoft.com/en-us/library/system.windows.forms.timer.aspx

System.Timers.Timer所指的类在此处描述:http: //msdn.microsoft.com/en-us/library/system.timers.timer.aspx

于 2012-06-14T11:04:59.623 回答
-1
    Imports System.Globalization


Public Class Form1
    Dim time As String = "00:00:00:00"
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

        Dim ci = CultureInfo.InvariantCulture

        Dim original As TimeSpan = TimeSpan.ParseExact(time, "dd\:hh\:mm\:ss", ci) 'ParseExact

        Dim difference As TimeSpan = TimeSpan.FromSeconds(1) ' = 1  Millisecond

        Dim final = original

        final = original + difference ' connect between original to difference !(00:00:00,000 + 1 MS = 00:00:00,001)!

        Dim output As String = final.ToString("dd\:hh\:mm\:ss", ci) 'convert to the format (  = 00:00:00,001  ) (Back It To The Right Format)

        time = output '!!Update!! the Time String from 00:00:00,000 To 00:00:00,001 |||| And in the Next Time 00:00:00,001 + 1 = 00:00:00,002

        Label1.Text = time 'Show the Time String in the label

    End Sub
End Class

这是工作脚本。IDK 为什么它有效,但它有效!:)

于 2017-09-20T12:09:46.950 回答