
QB4.5 CPU utilization in WINNT, WIN2000 etc
Quote:
>Whenever I run a program written in QB4.5 (even within the IDE) the task
>manager shows almost 100% cpu utilization even (or especially??) when
>the program is waiting for input. Two questions occur to me: 1) Is this
>normal behavior;
Yes. The problem is that the program is constantly looping to check the
keyboard buffer.
Quote:
>and 2) how do I get it to release the cpu when it is idle?
Try the following:
================================ Begin =================================
DEFINT A-Z
'$INCLUDE: 'qbx.bi'
DECLARE SUB DOSIdle ()
DECLARE FUNCTION Inkey% ()
DIM SHARED Regs AS RegType
'***********************************************************************
'* SUB DOSIdle
'*
'* PURPOSE
'* Uses DOS ISR 2FH, Function 1680H to give up a time slice to OS/2
'* or Windows.
'***********************************************************************
SUB DOSIdle
DIM RegsX AS RegTypeX
RegsX.ax = &H1680 'MS-DOS Idle call
InterruptX &H2F, RegsX, RegsX 'Call DOS
END SUB
'***********************************************************************
'* FUNCTION InKey%
'*
'* PURPOSE
'* Works similarly to BASIC's INKEY$ function, except the value
'* returned is an integer rather than a string, if the key pressed
'* is an extended key the value will be returned negated, and this
'* routine optionally waits until a key is pressed before it returns
'* control to the calling routine (set NoWait% to zero).
'***********************************************************************
FUNCTION InKey% (NoWait%) STATIC
DO
K$ = INKEY$ 'Check for a key
DOSIdle 'Give up idle time
LOOP UNTIL NoWait% OR LEN(K$) 'Wait for a key, unless
' NoWait% is TRUE
SELECT CASE LEN(K$) 'Was a key pressed?
CASE 1: InKey% = ASC(K$) 'Return ASCII value
CASE 2: InKey% = -ASC(RIGHT$(K$, 1)) 'Extended key, return ASCII
END SELECT ' value negated
END FUNCTION
================================= End ==================================
The idea is that you simply put in a call to SUB DOSIdle in your
keyboard polling loop.
------------------------------------------------------------------------
He that loseth wealth, loseth much; he that loseth friends, loseth more;
but he that loseth his spirit loseth all.
--Spanish Maxim
------------------------------------------------------------------------
Joe Negron from Bay Ridge, Brooklyn, NY, USA