线程池的计时器

来源:互联网 发布:nginx使用场景 编辑:程序博客网 时间:2024/06/06 07:12

#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();
}

原创粉丝点击