I had a user complaining about his computer being super slow. So I did the usual checks for spyware and viruses and found nothing. Windows Task Manager showed CPU usage at 100% perpetually. While watching Windows Task Manager and closing programs I found the culprit. Turned out to be a program I wrote with Macro Scheduler that included a non-modal dialog. Doing some testing I found this program caused high CPU usage on every computer I tried it on. Doing a little more testing I found that any script with a non-modal dialog caused the same excessively high CPU usage.
Getting to the point.. I discovered that putting a short wait in the ActionLoop cut the CPU usage down to 1 or 2%. The wait does not seem to affect the script adversely. Here is the non-modal dialog example from the help file with the wait inserted:
Dialog>Dialog1
Caption=Non-Modal Dialog
Width=402
Height=118
Top=177
Left=242
Button=Update,16,8,75,25,5
Button=Exit,16,48,75,25,6
Edit=msEdit1,104,8,121,Fred
ComboBox=msComboBox1,104,32,121,1%CRLF%2
Edit=msEdit2,104,56,121,
MainMenu=file,open(100),save(101),exit(2)
EndDialog>Dialog1
Show>Dialog1
Label>ActionLoop
GetDialogAction>Dialog1,r
if>r=5,Update
if>r=6,Close
if>r=2,exit
Wait>0.5
Goto>ActionLoop
Label>exit
SRT>Update
Let>Dialog1.msEdit2=%Dialog1.msEdit1% %Dialog1.msComboBox1%
ResetDialogAction>Dialog1
END>Update
SRT>Close
CloseDialog>Dialog1
Let>r=2
END>Close
Hopefully somebody will find this useful,
Dick
Non-modal dialogs cause high CPU usage
Moderators: Dorian (MJT support), JRL
Yes, surprise surprise, a tight loop uses CPU cycles. I'm sure I've said this many times on this forum. Force each iteration of a loop to yield to the processor by using a small Wait.
MJT Net Support
[email protected]
[email protected]