You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
> By the way, SLEEP 5000 = 5 sec.
>SLEEP 30000 = 5 min.
Whoa. I have simply GOT to start reading the "What's New" more carefully. ()
BTW..
> I´ve read a lot about the deeds of SLEEP I rather use another method
???
AFAIK, SLEEP() is efficient. My point was more "why check every (less than five minutes)" if you are not going to do anything EXCEPT every five minutes?
SLEEP 5000 instead of checking every 1 millisecond?
MCM
You may have a point there but since I´ve read a lot about the deeds of SLEEP I rather use another method.
No, the program does not have any dialogs or windows. I just stays in memory checking for the other program. It is a security program that takes action when it does not detect the other program in memory.
By the way, SLEEP 5000 = 5 sec.
SLEEP 30000 = 5 min.
I may use DIALOG DOEVENTS 1000 or DIALOG DOEVENT 30000 instead. Whatever works best.
From BOB ZALE
"In PowerBASIC 8.04, the DIALOG DOEVENTS statement assumes an incorrect default value of zero (0) for the optional SLEEP& parameter. The correct default value should actually be one (1). This would cause execution to pause for 1 millisecond if there are no pending messages to process.
We recommend that all existing code be changed to add an explicit SLEEP& value of one (1) to all DIALOG DOEVENTS statements in your programs.
DIALOG DOEVENTS 1 -or- DIALOG DOEVENTS 1 TO count&
This will allow your programs to compile and execute correctly with both current versions and future versions of PowerBASIC. The correct default value for this parameter will be used in the next release of this compiler."
This was posted to the powerbase forum on Oct 21, 2007. KS
I have a program that sits in memory checking for the continuous presence of another program which must be running and which has setup its Mutex.
The code below shows what this program does while doing nothing. It just executes a loop, counting down the time lapsed until it is time to check again. In order to minimize CPU use I use the DIALOG DOEVENTS statement.
IF I compile this program with PB 7.04 it works nice. The CPU use as reported by the task administrator is 00. IF However I compile it using PB 8.04 the CPU use goes up to 99 in slow computers and somehow lower in faster computers. I haven´t installed PB 9.00 yet.
Any suggestions?
Code:
VerifyAgain:
' Check for Mutex
lpClassName = $MUTEX_SEGURIDAD1
lResult = App_PrevInstance(lpClassName)
' If the program we are checking is running, do nothing, wait, and check again.
IF lResult <> 0 THEN ' PROGRAM IS IN MEMORY
OriginalmenteEnMemoria = 1
' Wait 5 minutes to check again
InitialTime = TIMER
DO
CurrentTime = TIMER
DIALOG DOEVENTS
IF CurrentTime - InitialTime > PermanentWait THEN
' Once the wait time is up, check again
GOTO VerifyAgain
END IF
LOOP
END IF
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Leave a comment: