VC有没有等待函数

godidea 2006-01-04 04:40:06
让程序什么也不作,等待几秒钟再执行下面的程序
...全文
514 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
思危 2006-01-07
  • 打赏
  • 举报
回复
Sleep可以挂起当前线程
CUG122032 2006-01-07
  • 打赏
  • 举报
回复
比较常用的有timer和Sleep,用Sleep的好处是比较方便,它适用于对时间精度要求不高,而且时间间隔比较小的地方。timer用起来没有Sleep方便,它需要先安装计时器,不过Timer比Sleep功能更多一点。

对于你的问题,你说想让程序“什么都不做”,那就用Sleep。。。我想你要清楚你说的话,什么都不做,也包括不响应各种消息,也就是说你的任何操作都是无效的。比如你当时点了关闭按键,也要等Sleep结束才能响应。。。

所以还是用Timer 比较好,我觉得。...我只在调试的时候用Sleep,比如说你要编个人工智能的类,一开始的时候只有接口,内部还没有写,这时就在内部让它Sleep几秒,模仿它将来要运算所花的时间。。。。
vcmute 2006-01-07
  • 打赏
  • 举报
回复
Using Waitable Timer Objects
The following example creates a timer that will be signaled after a 10 second delay. First, the code uses the CreateWaitableTimer function to create a waitable timer object. Then it uses the SetWaitableTimer function to set the timer. The code uses the WaitForSingleObject function to determine when the timer has been signaled.

#include <windows.h>
#include <stdio.h>

int main()
{
HANDLE hTimer = NULL;
LARGE_INTEGER liDueTime;

liDueTime.QuadPart=-100000000;

// Create a waitable timer.
hTimer = CreateWaitableTimer(NULL, TRUE, "WaitableTimer");
if (!hTimer)
{
printf("CreateWaitableTimer failed (%d)\n", GetLastError());
return 1;
}

printf("Waiting for 10 seconds...\n");

// Set a timer to wait for 10 seconds.
if (!SetWaitableTimer(
hTimer, &liDueTime, 0, NULL, NULL, 0))
{
printf("SetWaitableTimer failed (%d)\n", GetLastError());
return 2;
}

// Wait for the timer.

if (WaitForSingleObject(hTimer, INFINITE) != WAIT_OBJECT_0)
printf("WaitForSingleObject failed (%d)\n", GetLastError());
else printf("Timer was signaled.\n");

return 0;
}
xxfyath 2006-01-07
  • 打赏
  • 举报
回复


Sleep(1000) ; ////等待1秒。


long lStartTime ;
lStartTime = GetTickCount() ;
for(;;)
if( GetTickCount() - lStartTime > 1000 ) break;


rageliu 2006-01-04
  • 打赏
  • 举报
回复
for()
while()
sleep()
Seu_why 2006-01-04
  • 打赏
  • 举报
回复
VOID Sleep(
DWORD dwMilliseconds // sleep time in milliseconds
);
pomelowu 2006-01-04
  • 打赏
  • 举报
回复
Sleep(3000); // sleep for 3 seconds
HelloIvan2005 2006-01-04
  • 打赏
  • 举报
回复
void Sleep(
DWORD dwMilliseconds
);
HelloIvan2005 2006-01-04
  • 打赏
  • 举报
回复
sleep();

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧