| Wait Window "" timeout 0.01 and Sleep(10) in VFP-9 |
|
| Author |
Message |
Docpro777

|
Posted: Visual FoxPro General, Wait Window "" timeout 0.01 and Sleep(10) in VFP-9 |
Top |
At times my VFP processing requires *rest(s)* it seems. (report processing/printing, various functions, .BeforeRowColChange events, etc.)
I've *discovered*:
Wait Window "" timeout 0.01 && ... helps at times
while the preferred:
Windows API Sleep() routines && ...I've had NO success with API Sleep() declarations
Any general or specific feedback concerning *rest(s)* in VFP-9 is appreciated.
Visual FoxPro1
|
| |
|
| |
 |
CetinBasoz

|
Posted: Visual FoxPro General, Wait Window "" timeout 0.01 and Sleep(10) in VFP-9 |
Top |
I have also seen messages stating a wait would cure some problem. But for myself I didn't have a need for such a thing from foxbase to VFP9. In other words I don't think VFP processing needs such *rests*.
|
| |
|
| |
 |
Docpro777

|
Posted: Visual FoxPro General, Wait Window "" timeout 0.01 and Sleep(10) in VFP-9 |
Top |
| I
have also seen messages stating a wait would cure some problem. But for
myself I didn't have a need for such a thing from foxbase to VFP9. In
other words I don't think VFP processing needs such *rests*. |
|
Thank you for your thoughtful words.
Interesting,
I erroneously concluded this was somewhat of a norm. I stand
corrected. I'm sure my crazy coding is 99.99% - 100% of the problem.
Albeit, I've used 'wait' about 300 hundred times as a work-around for
my bugs.
My coding glitches are fairly uniform within all VFP
versions and all Windows versions. Do you think its probable I'm
triggering circular events, keypress loops, or something
Admittedly,
because I am a self-taught VFP amateur ... and ... haven't really
mastered the VFP debugger(s), I've resorted to wait window commands to
test code ... and ... repeatedly stumbled upon 'wait' as the
work-around 'cure' in this way.
Any additonal thoughts as to
what mechanism might be involved where 'wait' is the 'work-around' for
my 'buggish' coding ... would be greatly appreciated.
|
| |
|
| |
 |
CetinBasoz

|
Posted: Visual FoxPro General, Wait Window "" timeout 0.01 and Sleep(10) in VFP-9 |
Top |
I don't know what might be the problem in your case. Sometimes it helps to see "the problem code".
Trace aware foundation class might help (I have never used myself) for debugging code when there are timers.
PS: I'm a self taught programmer too.
|
| |
|
| |
 |
AndyKr

|
Posted: Visual FoxPro General, Wait Window "" timeout 0.01 and Sleep(10) in VFP-9 |
Top |
>> Interesting, I erroneously concluded this was somewhat of a norm.
There certainly are cases where VFP processing is interrupted by the necessity to process windows events (you can control this to some extent with the DOEVENTS command) and of course, if you are reading a large amount of data into memory there can be delays while VFP handles the swapping out to disk (a notoriously slow process!) as it pages out existing memory to make way for new stuff. I have also seen some cases where it is necessary to introduce a pause into VFP to let windows catch up :)
However, none of these secnarios are really common, which is not to say that I doubt you in any way, but I would be very interested to see some code that really requires a "WAIT" to see if it is something inherent ot VFP that I am missing or whether it could be machine specific...
|
| |
|
| |
 |
Docpro777

|
Posted: Visual FoxPro General, Wait Window "" timeout 0.01 and Sleep(10) in VFP-9 |
Top |
| I
would be very interested to see some code that really requires a "WAIT" ... |
|
Here's the latest piece that *requires* a wait: in a
myToolbar.myTextControl.gotfocus. The wait (somehow) enables
.backcolor to actually be a red-light during SQL-Select processing (line 2,5,
and 6).
To Cetin Basoz and Andy Kramek,
IF RECCOUNT('cPatient')=0
this.BackColor= RGB(255,0,0)
Local lalias
lalias=Alias()
WAIT WINDOW '' TIMEOUT 0.001
Select Allt(patient.first_name)+' '+ patient.last_name As PatientName,Record From patient;
UNION (Select Allt(patient.last_name)+', '+ patient.first_name As PatientName,Record From patient);
ORDER By PatientName Into Cursor cPatient
Index On PatientName Tag 'PtName' &&test only
WAIT CLEAR
SELECT (lalias)
Endif
this.BackColor= RGB(255,255,0)
Without the wait command only the yellow .backcolor (last line) takes effect.
Note. WinAPI Sleep() fails to help.
|
| |
|
| |
 |
Docpro777

|
Posted: Visual FoxPro General, Wait Window "" timeout 0.01 and Sleep(10) in VFP-9 |
Top |
|
| |
 |
AndyKr

|
Posted: Visual FoxPro General, Wait Window "" timeout 0.01 and Sleep(10) in VFP-9 |
Top |
Hmm, I don't see the need for the WAIT here. I think this is one of those cases where VFP is queuing the events andspeed is the issue. Try using this code instead - you should see the code stop (I do)
IF RECCOUNT('cPatient')=0 this.BackColor= RGB(255,0,0) *** Force a refresh here This.Refresh() *** Is the backcolor actually set IF This.BackColor = RGB( 255,0,0) SET STEP ON ENDIF Local lalias lalias=Alias() Select Allt(patient.first_name)+' '+ patient.last_name As PatientName,Record From patient; UNION (Select Allt(patient.last_name)+', '+ patient.first_name As PatientName,Record From patient); ORDER By PatientName Into Cursor cPatient Index On PatientName Tag 'PtName' &&test only SELECT (lalias) Endif this.BackColor= RGB(255,255,0)
|
| |
|
| |
 |
CetinBasoz

|
Posted: Visual FoxPro General, Wait Window "" timeout 0.01 and Sleep(10) in VFP-9 |
Top |
refresh is what you need. wait helping creating a wait state <g> but not the correct way.
|
| |
|
| |
 |
Docpro777

|
Posted: Visual FoxPro General, Wait Window "" timeout 0.01 and Sleep(10) in VFP-9 |
Top |
I tried this.refresh (as per Andy's example below and in other lines therein). And still there is no 'red-light' (in .backcolor).
I may try to find another example, later. Thanks for you insight.
|
| |
|
| |
 |
Docpro777

|
Posted: Visual FoxPro General, Wait Window "" timeout 0.01 and Sleep(10) in VFP-9 |
Top |
Andy, I've tried your code (verbatum) and with multiple other lines of refresh as well. All this to no 'correct' solution. Unfortunately, I'm deficient with the VFP-debugger and have been compiling a My.Exe (vs. a My.App) (with a conjoined MySplash.exe) ... and/or may be a little obsessive-compulsive here.
Thus I altered your 'set step' line as a wait window ...
this.BackColor= RGB(255,0,0) *** Force a refresh here This.Refresh() *** Is the backcolor actually set IF This.BackColor = RGB( 255,0,0) WAIT WINDOW this.BackColor && 255 appears in the window ENDIF
*Of course* the wait window itself *corrects* the problem: a red-light (.backcolor) *faithfully* appears before the yellow .backColor.
To further test my curious logic I tried sleep() 3 times (below)
IF RECCOUNT('cPatient')=0 this.Refresh sleep(10) this.BackColor= RGB(255,0,0) this.Refresh sleep(10) Local lalias lalias=Alias() sleep(10) Select Allt(patient.first_name)+' '+ patient.last_name As PatientName,Record From patient; UNION (Select Allt(patient.last_name)+', '+ patient.first_name As PatientName,Record From patient); ORDER By PatientName Into Cursor cPatient Index On PatientName Tag 'PtName' &&test only sleep(10) SELECT (lalias) Endif this.BackColor= RGB(255,255,0)
Still no dice: Sleep() (as I stated initially) has never been a work-around for me. Nontheless, I will try refresh in other scenarios where I've used 'wait' as a work-around.
|
| |
|
| |
 |
AndyKr

|
Posted: Visual FoxPro General, Wait Window "" timeout 0.01 and Sleep(10) in VFP-9 |
Top |
>> *Of course* the wait window itself *corrects* the problem: a red-light (.backcolor) *faithfully* appears before the yellow .backColor.
As I said, the issue is one of timing. VFP attempts to optimize the screen updates (which are slow) by queuing events and handling them in 'idle' moments. The issue here is that the setting of Red actually DOES occur, but the screen is not actually being refreshed and so you don't see it until after the next color change (i.e. to yellow). The reason the WAIT helps is that it FORCES an immediate re-paint of the screen.
There are other ways to do this, and this is why SLEEP is no substitute - it does not force a refresh of the screen. You could try calling the Toolbar PAINT event as another possibility - the point is that it is not a 'problem', just a consequence of the VFP optimization.
|
| |
|
| |
 |
CetinBasoz

|
Posted: Visual FoxPro General, Wait Window "" timeout 0.01 and Sleep(10) in VFP-9 |
Top |
I overlooked your code, sorry. You don't need any code. It looks like after setting it to red your code is running fast and reaching "yellow". You're not seeing the change from speed despite it really changes (a human eye can notice 16 frames a second as far as I remember). Let's try to reproduce:
Public oForm oForm = Createobject('myForm') oForm.Show
Define Class myForm As Form Add Object txt1 As TextBox Add Object txt2 As TextBox With Top = 30,Left = 10 Add Object txt3 As TextBox With Top = 60,Left = 10
Procedure txt2.GotFocus This.BackColor =255 For ix = 1 To 100 EndFor This.BackColor=65535 EndProc Procedure txt3.GotFocus This.BackColor =255 For ix = 1 To 1000000 Endfor This.BackColor=65535 Endproc Enddefine
First one reaches the last line so fast that setting to red is not visible.
|
| |
|
| |
 |
Docpro777

|
Posted: Visual FoxPro General, Wait Window "" timeout 0.01 and Sleep(10) in VFP-9 |
Top |
Very well, thank you (and Cetin) for your indepth help about using 'wait' and what is occuring.
|
| |
|
| |
 |
Docpro777

|
Posted: Visual FoxPro General, Wait Window "" timeout 0.01 and Sleep(10) in VFP-9 |
Top |
Cetin, this is true for your code scenario. But for my .gotfocus SQL-Select statement it takes about 3+ long seconds to create the cursor, a time period which the eye well-perceives ... i.e.,
Select Allt(patient.first_name)+' '+ patient.last_name As PatientName,Record From patient; UNION (Select Allt(patient.last_name)+', '+ patient.first_name As PatientName,Record From patient);
UNION (...this...);
UNION (..that...);
UNION (..another...);
UNION (..yet another...);
ORDER By PatientName Into Cursor cPatient Select cPatient Set filter to pSearchString *etc.
Andy suggested there seems to be the effects of optimization or something affecting the refresh (which you seemed to suggest before).
At any rate, last night I found myself using 'Wait window "" timeout 0.001 in several instances to help the eye perceive the wait state (red light) for SQL to build on large tables
|
| |
|
| |
 |
| |
|