// shutdown all thread in the pool
for (int32 ithread = 0; ithread < icurthreadsinpool; ++ithread)
{
unsafe
{
bool bret = postqueuedcompletionstatus(gethandle, 4, (uint32*) shutdown_iocpthread, null);
}
}
// wait here until all the threads are gone
while (getcurthreadsinpool != 0) thread.sleep(100);
unsafe
{
// close the iocp handle
closehandle(gethandle);
}
}
catch
{
}
}
the only private method is the iocpfunction method. this method is spawned as a thread and is made part of the iocp thread pool by calling the getqueuedcompletionstatus win32 api method. when the getqueuedcompletionstatus win32 api method returns, we check to make sure we are not being asked to shutdown the thread. the third argument is the data associated with the posted work. if the data is not shutdown_iocpthread, then real work has been posted into the iocp thread pool and this thread has been chosen to process the work. the application developer’s supplied user function is called since the application developer is the only one who knows what needs to be done. once that is complete, the method checks if a new thread should be added to the pool. this is done by reviewing the number of active threads in the pool.