Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » TopWindow&PopUp, TrayIcon » How often is Update called? Is there a similiar frequently called method?
How often is Update called? Is there a similiar frequently called method? [message #50181] Fri, 17 August 2018 14:53 Go to next message
rafiwui is currently offline  rafiwui
Messages: 105
Registered: June 2017
Location: Stuttgart, Germany
Experienced Member
I am not sure if this fits in here but because in my specific case it's about TopWindow it should be okay.

So the thing is, I need to run a method that is working in the background (or better every "frame" if that exists). It should start getting called after the window got shown.
So I searched a bit here in the forum and in the documentation and I tried calling it inside the virtual void State(int reason) method but that doesn't work (well I will get back to this a bit later) and I tried calling it inside the virtual void Updater() but that doesn't work as well because it does not get called frequently.

That is leading me to my question in the title:
How often is Update() called?
And because I think that it does not happen very often: Is there a virtual method or a CALLBACK that is called very frequently (1 or more times in a second)?

Getting back to the virtual void State(int reason) method I mentioned ealier:
It probably would work if I start a background thread here but because I want to avoid that I am asking the above question Wink


Greetings
Daniel
Re: How often is Update called? Is there a similiar frequently called method? [message #50182 is a reply to message #50181] Sat, 18 August 2018 13:53 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1758
Registered: August 2008
Location: Czech Republic
Senior Contributor

Hi Daniel,

If I remember correctly, the Update and similar methods are called "when necessary". Since U++ is event based GUI framework, pretty much everything just reacts to events (user input, timers etc.). There is not something you could define as "frame", as each Ctrl is updated independently and only when something changes.

I think what you actually want is SetTimeCallback. It allows you to launch either one time or periodic tasks on the same event loop as everything else. Just make sure that the work you actually do in each iteration does not take too long, otherwise it would block the GUI (but the same would hold in case of Update() or any other function that blocks the loop).

Best regards,
Honza
Re: How often is Update called? Is there a similiar frequently called method? [message #50191 is a reply to message #50181] Mon, 20 August 2018 09:59 Go to previous message
mirek is currently offline  mirek
Messages: 12017
Registered: November 2005
Ultimate Member
Using timer might solve your issue, if what you need to do is to e.g. periodically check something.

Alternative is to "invert" message loop, or basically make your code the message loop: Instead of .Run (or .Execute) start your code and into some place that is passed through frequently enought (like each 1ms), put

if(Ctrl::IsWaitingEvent())
   Ctrl::ProcessEvents();


This will read and process all GUI events.

Mirek
Previous Topic: BUG? EditInt / PromptOK not functioning as thought?
Next Topic: Dialog windows showing semi randomly on the task bar on Linux
Goto Forum:
  


Current Time: Wed Sep 18 15:22:59 CEST 2019

Total time taken to generate the page: 0.01742 seconds