Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I m trying to write a function in VS2010 C++ to auto refresh the data of the UI in every 30s.

I m trying to use sleep() as a delay function, but I find it doesn't work well.

Any good solutions for refreshing the data?
Posted

if you're doing this in a Window, have a look at the SetTimer()[^] function; it will send your window a WM_TIMER message at the appropriate interval - there's an example in that link
 
Share this answer
 
Why are you using a timer? You should rather just invalidate[^] your display whenever the data changes.
 
Share this answer
 
A third solution is to combine the idea from both solutions...

Essentially each time a change is made, a timer is used to delay the update. If another change occurs before the timer has elapsed, then their update will be combined.

But I would go with relatively small delay like 500 ms. But it depends on the application.

My solution would be appropriate when it take some time to process changes (say a few seconds) but you want to combine changes that occurs in a batch (for example, keyboard auto-repeat).
 
Share this answer
 

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