Non-modal dialogs cause high CPU usage

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
JRL
Automation Wizard
Posts: 3502
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Non-modal dialogs cause high CPU usage

Post by JRL » Thu Oct 27, 2005 4:16 am

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

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Thu Oct 27, 2005 7:43 am

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]

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Thu Oct 27, 2005 5:57 pm

I always watch my CPU usage when writing loops and add wait>.0005 in a couple of places depending on how long the loop is. That normally keeps the CPU usage very low, nothing worse than having your PC run at 100%.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts