The information in this article applies to:
SUMMARYOne method of implementing an ISAPI extension that can potentially require a long processing time (whether it is waiting on database queries or waiting on other network connections) is to implement a worker thread model. This ensures that the IIS Asynchronous Thread Queue (ATQ) thread is not tied up for long periods. While an example of implementing worker threads within an ISAPI extension is distributed with IIS 4.0, implementing a similar scheme using an ISAPI Wizard-generated MFC-based extension is not as clear-cut. This article demonstrates how to incorporate worker threads within an MFC-based extension. MORE INFORMATION
There are several steps involved in implementing worker threads within an
MFC based extension. The first step is to override the HttpExtensionProc()
virtual method found in the CHttpServer base class. This is very
straightforward. The sample code below assumes that a ISAPI Extension
Wizard project named MyApp has been created:
Completed SampleThe following files are available for download from the Microsoft Download Center. Click the file names below to download the files:MFCWkThr.exeFor more information about how to download files from the Microsoft Download Center, please visit the Download Center at the following Web address http://www.microsoft.com/downloads/search.aspand then click How to use the Microsoft Download Center. To build the sample, first extract the files into a directory, and open the project in Microsoft Visual C++. NOTE: This example uses a single worker thread per session. A more sophisticated and efficient model would use a pool of worker threads and a queuing mechanism to handle the multiple ECBs. Also remember, that while the ATQ thread is impersonating the IUSR_<MachineName> account, the newly spawned worker thread will be running in the security context of the local System account. To change to the IUSR_<MachineName> account, save the thread security token in the ATQ thread by calling OpenThreadToken() and pass that token along with the ECB to the worker thread and have the worker thread call SetThreadToken(). WARNING: The example above assumes all functions in the parse map will be using the worker thread model. If any function does not use a worker thread, you must notify CMyAppExtension::HttpExtensionProc() to not send back HSE_STATUS_PENDING. The simplest solution is to force all parse map functions to use worker threads. If this is not an acceptable solution, one way to notify the HttpExtensionProc() would be to use Thread Local Storage. If care is not taken to ensure the proper return flag is sent by the HttpExtensionProc(), you can potentially have sessions orphaned. REFERENCES
See \InetPub\iissamples\sdk\isapi\extensions\WorkerThread (distributed with
IIS 4.0) for example of implementing worker threads using non-MFC based
ISAPI extension.
Additional query words: kbDSupport kbdsi
Keywords : kbDSupport kbiis300 kbiis400 |
Last Reviewed: December 8, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |