【发布时间】:2012-06-14 10:55:24
【问题描述】:
我有一个间隔 = 1 的计时器
间隔 1 = 1 毫秒?
如果间隔 1 不是 1 毫秒,
那么告诉我哪个控制间隔 = 1ms
代码:
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,
但我认为它磨损了,因为计时器不计算毫秒
如果你有建议,请告诉我。
【问题讨论】:
-
From MSDN
The Windows Forms Timer component is single-threaded, and is limited to an accuracy of 55 milliseconds. If you require a multithreaded timer with greater accuracy, use the Timer class in the System.Timers namespace. -
你有 System.Timers 的例子吗?我需要计时器(1ms)
-
向我们展示创建计时器并开始计时的代码。它可能在
Main。它将包括类似Timer1.Interval = 1;。 -
或者不要打扰,因为正如史蒂夫所说,如果你真的需要每毫秒一个事件,这种计时器对你没有好处。我相当肯定
System.Timers不会超过 15 毫秒,因此也不能满足您的需求。您可能想查看stackoverflow.com/questions/3744032/… 了解更多信息。
标签: vb.net timer milliseconds