发表于:2008-09-02 13:23:30
3楼
先谢谢二位楼主。system.timers.timer 我试过了,结果还是一样。二楼的说法似乎有点道理,不过试了以后好像也不是。我把原码贴上,大家帮忙看一看。跑一段时间,实际的间隔时间增加大概 15ms, 而且是一直增加,请大虾们帮忙诊断一下。谢谢!
Private Sub ctrlthrd()
Do While CtrlThread.ThreadState = ThreadState.Running
IOvar.DelayTimer = 20
IOvar.ExitSysTimer = False
clsSysTimer.TimeProgram()
。。。。。。。
CtrlThread.Sleep(1)
Loop
End Sub
Public Class clsSysTimer
Private Shared MyTimer As New System.Windows.Forms.Timer
Private Shared ExitSysTimer As Boolean = False
Private Shared Sub TimerEventProcessor(ByVal myObject As Object, ByVal myEventArgs As EventArgs)
MyTimer.Stop
ExitSysTimer = True
End Sub
Public Shared Sub TimeProgram()
AddHandler MyTimer.Tick, AddressOf TimerEventProcessor
MyTimer.Interval = IOvar.DelayTimer
MyTimer.Start
While ExitSysTimer = False
'ExitSysTimer = True
Application.DoEvents()
End While
End Class