Microsoft KB Archive/268771

= FIX: DOEVENTS Command Runs Slowly =

Article ID: 268771

Article Last Modified on 4/3/2002

-

APPLIES TO


 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 5.0a
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q268771



SYMPTOMS
The DOEVENTS command allows your program to yield time to process Windows events. However, in tight loops, DOEVENTS waits for an excessive amount of time for an event.

WORKAROUND
Use the MOUSE command as shown in &quot;More Information&quot; to give DOEVENTS something to read.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

This problem was corrected in Microsoft Visual FoxPro version 7.0.



MORE INFORMATION
In order to reduce the previously described waiting time, following these steps:
 * 1) Move the mouse while you're waiting. (This is not considered to be an optimum solution.)
 * 2) Programmatically feed the app events for DOEVENTS to process.

The following code shows calling DOEVENTS in a tight loop, programmatically feeding the app events for DOEVENTS to process, and displaying the resulting times to perform the loops:   Copy the following code into a program file, and note the speed difference between the call to DOEVENTS and the call to FastDoEvents.NOTE: This code works better if there is actually a window open. If there is no window open, DOEVENTS and FastDoEvents have similar execution times, which fall between the times recorded with a window open. lnSeconds = SECONDS FOR i = 1 to 50 DOEVENTS ENDfor ? &quot;Total time: &quot; + STR(SECONDS - lnSeconds, 7, 4)

lnSeconds = SECONDS FOR i = 1 to 50 FastDoEvents ENDfor ? &quot;Total time: &quot; + STR(SECONDS - lnSeconds, 7, 4)

FUNCTION FastDoEvents LOCAL lnRow, lnCol, lcWindow

lcWindow = WONTOP

lnRow = MROW(lcWindow) lnCol = MCOL(lcWindow)

IF ( lnRow > 0 ) AND ( lnCol > 0 ) IF NOT EMPTY(lcWindow) MOUSE AT lnRow, lnCol WINDOW (lcWindow) ELSE MOUSE AT lnRow, lnCol ENDif ELSE KEYBOARD &quot; &quot; =INKEY ENDif

DOEVENTS RETURN 

