FIX: DOEVENTS Command Runs Slowly (268771)



The information in this article applies to:

  • Microsoft Visual FoxPro for Windows 5.0
  • Microsoft Visual FoxPro for Windows 5.0a
  • Microsoft Visual FoxPro for Windows 6.0

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 "More Information" 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:
  1. 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
    ? "Total time: " + STR(SECONDS() - lnSeconds, 7, 4)
    
    lnSeconds = SECONDS()
    FOR i = 1 to 50
       FastDoEvents()
    ENDfor
    ? "Total time: " + 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 " "
          =INKEY()
       ENDif
    
       DOEVENTS
    RETURN
    					

REFERENCES

For more information on the DOEVENTS and MOUSE commands, please see the Visual FoxPro Language Reference.

Modification Type:MajorLast Reviewed:4/3/2002
Keywords:kbbug kbCodeSnippet kbDSupport kbOOP KB268771