
Wait function not using any recources
Well - I think that your search is over
A few months ago I was wondering how VB manages to 'halt' the flow of
execution when you display a modal form.
That led me to do a little digging around - and I found something that
I've never seen mentioned on the NGs
the WaitMessage API
What it does is sit waiting for a Windows Message - unlike Sleep that
literally halts the thread - and unlike a DoEvents loop that 'eats'
CPU time.
While Something = False
WaitMessage
DoEvents
' Me.Print ".";
' DoEvents
Wend
Knock out the comment characters and you should see what it does.
Using this I have managed to port a DOS Touchscreen Application to
Windows - it uses something like 50 screens - but only one Form as I
paint all the screens myself.
The nice thing about it is that the code does _not_ have to be a
tangle of Events - all I do is paint a screen and wait until the user
'clicks' on a 'vector' - at which point it comes back with the 'key'
of the thing they clicked - the whole thing runs off the 'strand of
execution' from Sub Main
One could use this method to port DOS Applications that rely on InKey
My hunch is that this could also be used to 'supervise' normal
controls.
In your case you just release the WaitMessage loop using a flag set by
the timer and your code continues where you left off.
On Wed, 27 Mar 2002 09:30:34 +0100, "Goebel, Matthias"
Quote:
>I'm searching a function that i can call to wait for
>some seconds and which is not using any CPU-time.
>A simple loop with the 'doevents' command an checking
>the the system time uses 100% of CPU-Time.
>Now I am using the timer control-element to call a subroutine
>at 1 second interval for example and then counting the elapsed
>time.
>Does anyone know a better/easyer way to do this ?
>Matthias G"obel