Click here to Skip to main content
15,885,943 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Hello all
A lot of times I do enable/disable GUI elements in “OnIdle” according to the systems state (I’m aware, this is definitively not the way if determine the state costs CPU).

More and more I feel this is a lazy way and I become unhappy with this.

Can somebody confirm that this is a bad technique? If yes what is the better way?

Thanks a lot.
Regards
Posted
Comments
Sergey Alexandrovich Kryukov 4-May-12 15:41pm    
Reason for my vote of 5
Interesting enough, my 5 for the question.
--SA
Sandeep Mewara 4-May-12 15:43pm    
5 to your question and you.

1 solution

Yes and no. At least it is not obviously bad and widely used. It depends how you use it. It's hard to say without seeing the detail.

Best techniques are lazy: they can be sophisticated in fundamentals but lazy in ad-hoc usage; they should not require a lot of boring calculations and too much attention from a human being who happened to be an application developer.

Now, you lazy approach should be good only if you use the lazy pattern. In this case, nothing should happen to the system if you don't touch keyboard and mouse. If this is not true, that is, if something happens to the UI periodically, this certainly cannot be good. The state check cycle could be excessive; and you should be realistic in CPU usage: when something happens on one click, an extra millisecond does not count.

The best technique should work like this:

You can have some UI-wide StateDirty flag. A change in a single control should set this flag to true and send a UI-wide message which should trigger the full state update cycle. It's no too bad if the cycle is too excessive and often does not change everything, because an extra millisecond does not count. But it would be be acceptable if this happens periodically without user intervention. The UI should 100% sleep if nothing disturbs the system.

—SA
 
Share this answer
 
Comments
[no name] 4-May-12 13:18pm    
Wow! Thanks for this answer.
Regards, Bruno
Sergey Alexandrovich Kryukov 4-May-12 15:14pm    
You are very welcome.
--SA
Sandeep Mewara 4-May-12 15:13pm    
My 5! No idea who 1-voted it. :doh:
Sergey Alexandrovich Kryukov 4-May-12 15:17pm    
Thank you, Sandeep.
Well, that answer is not certain enough and can be considered questionable. I did not want to spend more time on it because platform and UI library were not specified. The idea to use the OnIdle (or something like that) is questionable, it should not be used literally. Someone could be a strong opponent of using the idle thing; and I did not explain properly that it should be used with care and how exactly...
--SA
[no name] 4-May-12 15:24pm    
More then properly enough for such a general question. I think with the details everybody has to fight by her/himself (sorry for my English). Thanks again!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900