遞增執行緒集區的執行緒計數。
語法
virtual VOID IncrementThreadCount(
VOID
) = 0;
參數
此方法不會採用任何參數。
傳回值
VOID.
備註
方法會將 IncrementThreadCount 執行緒集區的可用執行緒計數增加為單一線程。 計數不會超過執行緒集區 256 個執行緒的最大限制。
注意
IncrementThreadCount 實際上不會增加使用中的執行緒數目;只會影響執行緒計數。
當您開發執行需要長時間處理的作業的 HTTP 模組時,您的 HTTP 模組可以呼叫 IncrementThreadCount 來增加執行緒集區的可用執行緒,而您的模組執行長時間執行的作業。 當模組完成時,它會呼叫 IIHttpServer::D ecrementThreadCount 來還原執行緒計數。
範例
下列程式碼範例示範如何建立 HTTP IncrementThreadCount 模組,呼叫 以增加執行緒集區的執行緒計數,然後睡眠 30 秒。 模組接著會呼叫 DecrementThreadCount 以還原執行緒計數並結束。
#define _WINSOCKAPI_
#include <windows.h>
#include <sal.h>
#include <httpserv.h>
// Create a pointer for the global server interface.
IHttpServer * g_pHttpServer = NULL;
// Create the module class.
class MyHttpModule : public CHttpModule
{
public:
REQUEST_NOTIFICATION_STATUS
OnBeginRequest(
IN IHttpContext * pHttpContext,
IN IHttpEventProvider * pProvider
)
{
UNREFERENCED_PARAMETER( pHttpContext );
UNREFERENCED_PARAMETER( pProvider );
// Increment the thread count.
g_pHttpServer->IncrementThreadCount();
// Sleep for 30 seconds.
Sleep(30 * 1000);
// Decrement the thread count.
g_pHttpServer->DecrementThreadCount();
// Return processing to the pipeline.
return RQ_NOTIFICATION_CONTINUE;
}
};
// Create the module's class factory.
class MyHttpModuleFactory : public IHttpModuleFactory
{
public:
HRESULT
GetHttpModule(
OUT CHttpModule ** ppModule,
IN IModuleAllocator * pAllocator
)
{
UNREFERENCED_PARAMETER( pAllocator );
// Create a new instance.
MyHttpModule * pModule = new MyHttpModule;
// Test for an error.
if (!pModule)
{
// Return an error if the factory cannot create the instance.
return HRESULT_FROM_WIN32( ERROR_NOT_ENOUGH_MEMORY );
}
else
{
// Return a pointer to the module.
*ppModule = pModule;
pModule = NULL;
// Return a success status.
return S_OK;
}
}
void Terminate()
{
// Remove the class from memory.
delete this;
}
};
// Create the module's exported registration function.
HRESULT
__stdcall
RegisterModule(
DWORD dwServerVersion,
IHttpModuleRegistrationInfo * pModuleInfo,
IHttpServer * pGlobalInfo
)
{
UNREFERENCED_PARAMETER( dwServerVersion );
// Store the pointer for the global server interface.
g_pHttpServer = pGlobalInfo;
// Set the request notifications and exit.
return pModuleInfo->SetRequestNotifications(
new MyHttpModuleFactory,
RQ_BEGIN_REQUEST,
0
);
}
您的模組必須匯出 RegisterModule 函式 。 您可以為專案建立模組定義 (.def) 檔案,或使用 參數編譯模組 /EXPORT:RegisterModule 來匯出此函式。 如需詳細資訊,請參閱逐步解說 :使用機器碼建立Request-Level HTTP 模組。
您可以選擇性地使用呼叫慣例編譯器代碼, __stdcall (/Gz) 而不是明確宣告每個函式的呼叫慣例。
規格需求
| 類型 | 描述 |
|---|---|
| Client | - Windows Vista 上的 IIS 7.0 - Windows 7 上的 IIS 7.5 - Windows 8 上的 IIS 8.0 - Windows 10上的 IIS 10.0 |
| 伺服器 | - Windows Server 2008 上的 IIS 7.0 - Windows Server 2008 R2 上的 IIS 7.5 - Windows Server 2012 上的 IIS 8.0 - Windows Server 2012 R2 上的 IIS 8.5 - Windows Server 2016上的 IIS 10.0 |
| 產品 | - IIS 7.0、IIS 7.5、IIS 8.0、IIS 8.5、IIS 10.0 - IIS Express 7.5、IIS Express 8.0、IIS Express 10.0 |
| 標頭 | Httpserv.h |