您的位置:首页 > 大数据 > 人工智能

ns级定时器,CreateWaitableTimer和SetWaitableTimer

2011-10-25 10:28 381 查看
#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;

}

上面是MSDN的例子,SetWaitableTimer
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: