TActionlist, OnUpdate, High CPU Usage? [duplicate]

2019-09-11 05:18发布

问题:

This question already has an answer here:

  • Why are : visible, control assigned TActions affecting the CPU usage of the application? 2 answers

I use the TActionslists OnUpdate event to enable or disable the buttons in my application.
But I noticed my cpu using 25% of its capability.
When I remove the code triggerd on the event my cpu usage still remains 25%.
Only if I unhook the event completely does my cpu run at expected 1%.

It seems the OnUpdate event fires way to many times.
Is there a way to prevent this behavior?

回答1:

The VCL provides Application.ActionUpdateDelay to help in such situations. Set it to a non-zero value to force a delay between successive action updating.

However, it might be more prudent to find out why your action is forcing endless repeated OnIdle conditions. If you can stop it doing so then there's no need for update delay.