Every so often a function of the calling thread pool

step:

  1. Create a similar function void CALLBACK TimeoutCallBack (PTP_CALLBACK_INSTANCE pInstance, PVOID pvContext, PTP_TIMER pcbe) of

  2、CreateThreadpoolTimer

  3、SetThreadpoolTimer

  4、CloseThreadpoolTimer

understanding:

  In fact, the equivalent of a kernel object to wait, not on implementation, using a thread pool technology.

Code:

#include <iostream>
#include <afx.h>
using namespace std;

void CALLBACK TimeoutCallBack(
	PTP_CALLBACK_INSTANCE pInstance,
	PVOID pvContext,
	PTP_TIMER pcbe)
{
	cout << "线程ID:" << GetCurrentThreadId() << endl;
}

void main()
{
	PTP_TIMER pTimer = CreateThreadpoolTimer(TimeoutCallBack, NULL, NULL);
	
	SYSTEMTIME st;
	FILETIME ftLocal, ftUTC;
	LARGE_INTEGER liUTC;

	st.wYear = 2013;
	st.wMonth = 9;
	st.wDay = 26;
	st.wDayOfWeek = 0;
	st.wHour = 12;
	st.wMinute = 46;
	st.wSecond = 0;
	st.wMilliseconds = 0;

	SystemTimeToFileTime(&st, &ftLocal);
	LocalFileTimeToFileTime(&ftLocal, &ftUTC);

	liUTC.LowPart = ftUTC.dwLowDateTime;
	liUTC.HighPart = ftUTC.dwHighDateTime;

	SetThreadpoolTimer(pTimer, &ftUTC, 1000, 0);

	Sleep(2000);

	WaitForThreadpoolTimerCallbacks(pTimer, TRUE);

	CloseThreadpoolTimer(pTimer);
}

 result:

  

 

Reproduced in: https: //www.cnblogs.com/wang-can/p/3340591.html

Guess you like

Origin blog.csdn.net/weixin_33753845/article/details/94063611