Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
What's wrong?
Message
From
01/10/2004 11:56:00
 
 
To
01/10/2004 09:25:00
Km Kwun
Eastop Consultants Limited
Nt, Hong Kong
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00947862
Message ID:
00947970
Views:
15
You and Fabio have enlightened me! I really thought that inkey() consumes a lot of processor time. Now I see that it's not the case. That is good to know! This is a nice example of how even a bad answer can be of help in clarifying the workings of vfp. Thanks to both of you.

>This seems to be untrue. Run this program and open Task Manager to watch the CPU usage:
>
>
>Declare Sleep In WIN32API Integer nMillisecs
>? 'Caps Lock to stop. Num Lock to toggle Sleep() and Inkey()'
>Do While !Capslock()
>	If Numlock()
>		? 'Sleep'
>		Sleep(1000)
>	Else
>		? 'Inkey'
>		Inkey(1)
>	EndIf
>EndDo
>
>
>KM
>
>
>>SLEEP(1000) has a BIG advantage over inkey(1). It does not eat all processor time! Actually, it amply uses processor time. Inkey(1) consumes almost 100 percent.
>>
>>>Hi Fabio,
>>>
>>>Thank for confirming that this is a bug of INKEY(1). I solved the problem by replacing it with the SLEEP() API function.
>>>
>>>This is an application to monitor the content change of a special shared folder. Every second, it writes a summary of the content change into a new record of a DBF (also displayed on screen using "?") for future analysis. There is neither any form nor control on the screen.
>>>
>>>I use a loop rather than the Timer because it is simpler and easier to stepping through to debug.
>>>
>>>Very often, the application is run unattendedly as a scheduled task. Therefore "ON SHUTDOWN ..." is necessary so that the running task can be stopped by choosing the STOP option of the Windows Scheduler menu.
>>>
>>>KM
>>>
>>>
>>>>>Can anybody tell me what's wrong with this code? Or, can anybody suggest a workaround?
>>>>>
>>>>>
>>>>>x=.T.
>>>>>On Shutdown x=.F.
>>>>>
>>>>>o=Createobject('MyClass')
>>>>>
>>>>>Define Class MyClass As Custom
>>>>>	Function Init
>>>>>	Do While x
>>>>>		? Datetime()
>>>>>		=Inkey(1)
>>>>>	EndDo
>>>>>EndDefine
>>>>>
>>>>>
>>>>>In either development time or run time, when we try to close the application, VFP crashes!
>>>>>
>>>>>TIA
>>>>
>>>>A bug.
>>>>
>>>>Crash into VFP8 and VFP9b
>>>>
>>>>Preconditions:
>>>>- On Shutdown is not empty
>>>>- VFP wait for a keypress with INKEY() or CHRSAW()
>>>>-
_VFP
process a WM_CLOSE message
>>>>
>>>>A more simple repro:
>>>>
>>>>DECLARE SHORT PostMessage IN user32;
>>>>    INTEGER   hWnd,;
>>>>    INTEGER   Msg,;
>>>>    INTEGER   wParam,;
>>>>    INTEGER   lParam
>>>>
>>>>On Shutdown KEYBOARD '{SPACEBAR}'
>>>>
>>>>=PostMessage(_VFP.hWnd,16,0,0)
>>>>=CHRSAW(1)
>>>>
>>>>
>>>>WorkAround:
>>>>use READ EVENTS
>>>>Fabio
Groet,
Peter de Valença

Constructive frustration is the breeding ground of genius.
If there’s no willingness to moderate for the sake of good debate, then I have no willingness to debate at all.
Let's develop superb standards that will end the holy wars.
"There are three types of people: Alphas and Betas", said the beta decisively.
If you find this message rude or offensive or stupid, please take a step away from the keyboard and try to think calmly about an eventual a possible alternative explanation of my message.
Previous
Reply
Map
View

Click here to load this message in the networking platform