线程池的计时器

#include "stdafx.h"
#include
#include
#include
#include
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();
}

你可能感兴趣的:(windows)