线程池就好像一个池子,可以容纳各种液体

线程池就好像一个池子,可以容纳各种液体。
在《windows核心编程》中提及了win2000的新的线程池概念,以及一个新函数,很好用,但vc6.0不支持该函数(MSDN上有),可以直接调用库里的函数,看了该函数,应该对线程池有很好的了解。我曾作了个测试:
typedef VOID (WINAPI *WAITORTIMERCALLBACK)(PVOID,BOOLEAN);

typedef BOOL (FAR PASCAL * FUNC2)(
PHANDLE phNewWaitObject, // wait handle
HANDLE hObject, // handle to object
WAITORTIMERCALLBACK Callback, // timer callback function
PVOID Context, // callback function parameter
ULONG dwMilliseconds, // time-out interval
ULONG dwFlags // options
);

VOID CALLBACK ExeClient(PVOID pvContext,BOOLEAN fTimerOrWaitFired)
{
if(fTimerOrWaitFired)
AfxMessageBox("超时了");
else
AfxMessageBox("触发事件到达!");
}

HANDLE hWaitHandle;
void CDrapFileDlg::OnButton2()
{
// TODO: Add your control notification handler code here
HANDLE phNewWaitObject;
FUNC2 RegisterWaitForSingleObject;
HMODULE hModule = GetModuleHandle("Kernel32.dll");
RegisterWaitForSingleObject = (FUNC2) GetProcAddress (hModule, _T( "RegisterWaitForSingleObject" ) );
RegisterWaitForSingleObject(&phNewWaitObject,hWaitHandle,
ExeClient,NULL,4000,WT_EXECUTEDEFAULT);
}

void CDrapFileDlg::OnButton3() //取消
{
// TODO: Add your control notification handler code here
PulseEvent(hWaitHandle);

}

你可能感兴趣的:(线程池)