What is the accuracy of the Delay() function? Is background processing occurs…

Knowledge Base Article # Q200084

Read Prior Article Read Next Article
Summary Explains how to calculate the accuracy of Delay() function and whether some processing occurs while the Delay() is processed
  
Login to rate article
Delay() is accurate to 1msec, however, since the Delay() function allows form events and interrupts to be dispatched, it may not always be accurate to 1msec. You can use the Sleep() function if you would like to completely suspend the thread and get better accuracy , however your form events will not be dispatched and will look frozen until Sleep is returned (if sleep is called in the form thread). The SetThreadPriority() may also be used to improve accuracy. While delay is processing an event is, the delay can only return after the event is executed, so make sure the event processing time is short as possible.

If you still want to process events while you are waiting but want to consume less CPU, use the Tick() function to implement your own delay and allow other processing such as interrupts, form events and other custom processing while doing it. You should call WaitForEvent() function to suspend the thread and consume less CPU while waiting to the next event resulting in a better delay function as in the following example:

lStart=tick()
while tick()-lStart
    ! optional  - do something

    ! suspend to conserve CPU but still allow form events interrupts etc
    WaitForEvent(tick()-lStart)

endwhile


Article Date 3/13/2007
Keywords ATEasy, Delay, Tick, WaitForEvent, Sleep, SetThreadPriority


Login to rate article

Read Prior Article Read Next Article
>