如何在VS2010 C ++中编写延迟函数 [英] How to write a delay function in VS2010 C++
本文介绍了如何在VS2010 C ++中编写延迟函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在VS2010 C ++中编写一个函数,以每30秒自动刷新一次UI数据.
我正在尝试将sleep()用作延迟函数,但是我发现它不能很好地工作.
解决方案
如果在Window中进行此操作,请查看 ^ ]函数;它将以适当的时间间隔向您的窗口发送WM_TIMER
消息-该链接中有一个示例
您为什么使用计时器?您宁可无效 [ 解决方案
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
Why are you using a timer? You should rather just invalidate[^] your display whenever the data changes.
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).
这篇关于如何在VS2010 C ++中编写延迟函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文