I wrote the below function to sleep, while processing the window events. It works well enough, but I'd like to improve the accuracy of the sleep. Example - If you call it with 10 msec (0.010), it can take up to 15 msec of real time before it exits. Any suggestions on making it closer to 10 msec?
Code:Public Sub Spin(ByVal TimeInSec As Double) Dim tsStart As TimeSpan = Date.Now.TimeOfDay Dim tsNext As TimeSpan = tsStart Dim TimeSlept As Double = tsNext.TotalSeconds - tsStart.TotalSeconds 'wait for Time seconds While TimeSlept < TimeInSec AndAlso TimeSlept >= 0 AndAlso AbortTest() = False System.Windows.Forms.Application.DoEvents() Sleep(2) tsNext = Date.Now.TimeOfDay TimeSlept = tsNext.TotalSeconds - tsStart.TotalSeconds End While End Sub




Reply With Quote