在不占用CPU时间的情况下,在C ++中实现Sleep()或暂停功能的最佳方法 [英] Best way to implement Sleep() or pause function in C++ without hogging CPU time

查看:687
本文介绍了在不占用CPU时间的情况下,在C ++中实现Sleep()或暂停功能的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现不占用大量CPU时间的Sleep()函数。

I am trying to implement the Sleep() function that does not take a lot of CPU time.

在VBA中,我能够使用"DoEvents"。做这样的事情:

In VBA, I was able to use "DoEvents" to do something like this:

等待(Dim wait_time)

Wait (Dim wait_time)

Dim a

Dim i

a = wait_time / 10

a = wait_time / 10

虽然我< a

睡眠(10)

DoEvents

i = i + 1

i = i +1

所以基本上我在等待时使用DoEvents来允许其他进程运行。

So basically I use DoEvents to allow other processes to run while I wait.

C ++中有类似的东西吗? VBA"DoEvents"?

Is there anything similar in C++ similar to VBA "DoEvents"?

推荐答案

只需调用Sleep API即可。睡觉时不消耗CPU时间。 它暂停指定时间的调用线程。

Simply call the Sleep API. It does not consume CPU time while sleeping.  It suspends the calling thread for the specified time.


这篇关于在不占用CPU时间的情况下,在C ++中实现Sleep()或暂停功能的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆