I wrote an ISAPI extension in C++ whose purpose is to run PowerBuilder code in IIS. PowerBuilder has an interface to allow C++ code to call directly into PowerBuilder code.
One of the features allows it to kick off a background thread using CreateThread and return to the client before the background thread is finished.
One of the users is having a problem where if two client apps request the same thing at about the same time, one of them aborts at a certain point in the PowerBuilder code executed by the background thread.
In IIS the AppPool is a process and each request is a thread. If two request threads can successfully run PowerBuilder code at the same time, why can't threads created by the request threads run successfully?
What I have tried:
This is the code that kicks off the background thread:
if (RunBackground) {
hThread = CreateThread(NULL, 0, BackgroundThread, strArgument, 0, &dwThreadID);
if (hThread != NULL) {
if (strArgument->hEvent != NULL) {
WaitForSingleObject(strArgument->hEvent, INFINITE);
}
delete strArgument;
CloseHandle(hThread);
CloseHandle(strArgument->hEvent);
pECB->dwHttpStatusCode = HTTP_STATUS_OK;
return HSE_STATUS_PENDING;
}
}
The BackgroundThread function initializes the PowerBuilder runtime and before calling the user code, does the following:
if (strArgument->hEvent != NULL) {
SetEvent(strArgument->hEvent);
}
pECB->ServerSupportFunction(pECB->ConnID, HSE_REQ_DONE_WITH_SESSION, NULL, NULL, NULL);