#include"stdafx.h"
#include<windows.h>
#include<iostream>
using namespace std;
void CALLBACK Work(PTP_CALLBACK_INSTANCE instance,PVOID context,PTP_WORK work)
{
int *p=static_cast<int*>(context);
cout<<"id="<<GetCurrentThreadId()<<" "<<*p<<endl;
//getc(stdin);
}
void CALLBACK Timer(PTP_CALLBACK_INSTANCE instance,PVOID context,PTP_TIMER work)
{
static UINT32 cnt= 0;
if(++cnt>5)CloseThreadpoolTimer(work);
int *p=static_cast<int*>(context);
cout<<"timer="<<GetCurrentThreadId()<<" "<<*p<<cnt<<endl;
//getc(stdin);
}
int _tmain()
{
INT context=0;
PTP_WORK wo= CreateThreadpoolWork(Work,&context,NULL);
SubmitThreadpoolWork(wo);Sleep(1);
SubmitThreadpoolWork(wo);Sleep(1);
SubmitThreadpoolWork(wo);Sleep(1);
context =1;
PTP_WORK w1= CreateThreadpoolWork(Work,&context,NULL);
SubmitThreadpoolWork(w1);
///WaitForThreadpoolWorkCallbacks(w1,TRUE);
WaitForThreadpoolWorkCallbacks(w1,FALSE);
PTP_TIMER t = CreateThreadpoolTimer(Timer,&context,NULL);
FILETIME due;
due.dwLowDateTime=-1;
due.dwHighDateTime=0;
SetThreadpoolTimer(t,&due,500,0);
while(1)Sleep(1000);
return 0;
}