Article ID: 185518 - Last Review: July 3, 2008 - Revision: 4.1 How to implement worker threads using MFC ISAPI extensionThis article was previously published under Q185518 We strongly recommend that all users upgrade to Microsoft Internet Information Services (IIS) version 7.0 running on Microsoft Windows Server 2008. IIS 7.0 significantly increases Web infrastructure security. For more information about IIS security-related topics, visit the following Microsoft Web site: http://www.microsoft.com/technet/security/prodtech/IIS.mspx
(http://www.microsoft.com/technet/security/prodtech/IIS.mspx)
For more information about IIS 7.0, visit the following Microsoft Web site: http://www.iis.net/default.aspx?tabid=1
(http://www.iis.net/default.aspx?tabid=1)
On This PageSUMMARY
One 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 the platform SDK, 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:MFCWkThr.exe
(http://download.microsoft.com/download/ie4095/sample44/1/w9xnt4/en-us/mfcwkthr.exe)
For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:
119591
(http://support.microsoft.com/kb/119591/EN-US/
)
How to Obtain Microsoft Support Files from Online Services
Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file.
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. REFERENCESFor additional information, click the article number below
to view the article in the Microsoft Knowledge Base:
197728
(http://support.microsoft.com/kb/197728/EN-US/
)
Creating a Thread Pool for MFC-Based ISAPI Extensions
See Thread Local Storage in Win32 API Documentation. APPLIES TO
| Article Translations
|
Back to the top
