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
#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
相关文章推荐
- windows 下,用CreateWaitableTimer SetWaitableTimer 创建定时器(用轮询的办法保持高精度)
- CreateWaitableTimer和SetWaitableTimer
- Windows API CreateWaitableTimer和SetWaitableTimer
- 搜集的一些关于CreateWaitableTimer的资料_等待定时器(转载) 2010-12-14 11:11
- CreateWaitableTimer和SetWaitableTimer函数(定时器)
- Windows API CreateWaitableTimer和SetWaitableTimer
- CreateWaitableTimer与SetWaitableTimer详解
- 线程同步 等待定时器 WaitableTimer 内核对象 CreateWaitableTimer
- CreateWaitableTimer和SetWaitableTimer函数(定时器)
- CreateWaitableTimer和SetWaitableTimer函数(定时器)
- CreateWaitableTimer和SetWaitableTimer函数(定时器)
- 定时器的使用 之 SetWaitableTimer
- 单线程使用 CreateWaitableTimer 和 SetWaitableTimer 设置定时周期
- CreateWaitableTimer和SetWaitableTimer函数(定时器)
- 搜集的一些关于CreateWaitableTimer的资料_等待定时器
- SetTimer and CreateWaitableTimer的例子(静态函数设置为回调函数,瑞士的网页,有点意思)
- CreateWaitableTimer和SetWaitableTimer函数(定时器)
- CreateWaitableTimer和SetWaitableTimer函数(定时器)
- 搜集的一些关于CreateWaitableTimer的资料_等待定时器
- Windows API一日一练(66)CreateWaitableTimer和SetWaitableTimer函数