DoEvents Procedure

Yields execution so that ATEasy can process other events.

Syntax

DoEvents ()

Comments

DoEvents passes control to ATEasy.  Control is returned after ATEasy has finished processing the events in its queue.

If you need to perform length processing in a form or a control event, make sure to call DoEvents in the loop (an example below). If not, the form will appear as non-responsive since ATEasy calls one event at a time and will not process other user actions until the event is closed.  Make sure also to disable some controls to avoid recursive (i.e. if user clicks twice on the same button, then the event will be called twice since the DoEvents is called).

Possible Problems with DoEvents

Examples

In addition to examples below, also refer to examples for forms in the forms.prj example in ATEasy Examples directory.

(1) Delay Loops - in the following example, the DoEvents procedure allows ATEasy to continue with any other pending jobs.
 

dwDWord=Tick()

loop

if Tick()-dwDWord>20   ! loop up to 20mSec

ExitLoop

endif

DoEvents()             ! use this in form/control event, no need if not called from a form/control event

WaitForEvent(1)        ! don't consume a lot of CPU, wait 1mSec max for the event

endloop

 

(2) Lengthy Form Event Operations - when you are using a form/control event to calculate or perform lengthy operations that takes more than one or two second, DoEvents() must be called - to allow the form events to be called while in the event:

 

btnClaculate.OnClick()

{

! protect this from calling more than once at a time since we call DoEvents here

! you can also disable the button instead btnClaculate.Enabled=False

If f_bInEvent than return

 

f_bInEvent=True

 

For i=0 to 10000
 

! do something that take a lot of time
...

! dispatch event to the form, paint, mouse, etc 

DoEvents()

Next

 

! you can also disable the button instead btnClaculate.Enabled=True

f_bInEvent=False

}

 

See Also

CreateThread, Delay, Load, Sleep, WaitForEvent