It recently came to my attention that some LB programmers were avoiding scan loops because they use 100% of the processor. Scan loops are necessary if you use WM_Liberty.dll or almost anything else that uses LB callbacks. Although the 100% usage is true there's a simple way to cure this. An api call to Sleep is all that's needed. The following two programs were tested on a PII 400 that had 27 tasks running in the background along with Liberty BASIC. As the pictures show the program without the Sleep call used 100% of the processor while the program with the sleep call used only 1%. That 1% included all of the other running tasks too.
'-------- 100%nomainwinopen"Use all of that cpu"forwindowas#1#1"trapclose [quit]"[loop]scangoto[loop][quit]close#1:end
'-------- 1%nomainwinopen"Minimun cpu uasage"forwindowas#1#1"trapclose [quit]"[loop]scan'sleep for 50 millisecondscalldll#kernel32,"Sleep",50asulong,r asvoidgoto[loop][quit]close#1:end
MINIMIZE CPU USAGE IN SCAN LOOP
-It recently came to my attention that some LB programmers were avoiding scan loops because they use 100% of the processor. Scan loops are necessary if you use WM_Liberty.dll or almost anything else that uses LB callbacks. Although the 100% usage is true there's a simple way to cure this. An api call to Sleep is all that's needed. The following two programs were tested on a PII 400 that had 27 tasks running in the background along with Liberty BASIC. As the pictures show the program without the Sleep call used 100% of the processor while the program with the sleep call used only 1%. That 1% included all of the other running tasks too.