#include "stdafx.h"
#include <conio.h>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
void CALLBACK TimeoutCallback(PTP_CALLBACK_INSTANCE, PVOID pvContext, PTP_TIMER pTimer)
{
long* count = (long*)pvContext;
InterlockedIncrement(count);
cout << GetCurrentThreadId() << "," << *count << 's' << endl;
}
void WaitForKeyboard()
{
while(!_kbhit());
}
void main()
{
PTP_TIMER pTimer = NULL;
long local = 0;
pTimer = CreateThreadpoolTimer(&TimeoutCallback, &local, NULL);
FILETIME ft = {-1, 0};
SetThreadpoolTimer(pTimer, &ft, 100, 0);
WaitForKeyboard();
}
C++线程池定时器示例
本文展示了一个使用C++实现的线程池定时器示例代码,该示例利用了CreateThreadpoolTimer创建定时器,并通过回调函数进行计数递增,最后通过键盘输入停止定时器。
1084

被折叠的 条评论
为什么被折叠?



