WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Functions

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Yield vs. Timedelay Functions

Keywords:        yield timedelay cpu processing processor speed

Question:

I'd like to implement the following - wait for control-shift to do some work. Currently, this works just fine on my machine (Win95) - just checking to make sure I don't need more than the YIELD (e.g. TIMEDELAY(1))
while @TRUE
if IsKeyDown(@CTRL & @SHIFT) == @YES then
DO SOME WORK
endif

yield 
endwhile 

Answer:

Yields really don't wait long enough for much. The Yield is a VERY short time, so the loop burns up substancial CPU time as it spins.

Try TimeDelay(1) (or TimeDelay(0.5) if you are impatient).

        TimeDelay(0.5) 
It really depends on how often you want to check. The TimeDelay function gives other running windows time to process messages, like the Yield function does.

Related Question when Running Winbatch as service: processor at 100% :

We are investigating the possibility of running a Winbatch program as a service on Windows NT 4.0. The initial test shows that the service is using 100% of the processor.

Yields(20) doesn't seem to have any influence on the situation. INSTSRV from the NT resource kit is used together with SRVANY to install the service. Is there any way to get the program to go to sleep or stop using so much processor capacity? The function INTCONTROL(1000,1,0,0,0) has been issued to let the program function as a service. All ideas will be very welcome.

Answer:

WinBatch isn't really *using* the cpu, more than anyone else is. If your coworkers doubt that, throw in a TimeDelay(1) or (2) if your program doesn't need to be truly active every millisecond. I've got a winbatch "service" taking 2% cpu 90% of the time, jumping considerably of course when it has something to do.

Reply:

Thanx for your (quick) response. Using the TimeDelay() function instead of the Yield() function works. CPU Usage dropped to 2%. Great tip!
Article ID:   W13127
Filename:   Yield versus TimeDelay.txt
File Created: 1999:04:15:16:51:56
Last Updated: 1999:04:15:16:51:56