Is it possble to terminate SynchronousRequest within a thread? I cannot use SynchronousRequestAsync.
Asked
Active
Viewed 36 times
1 Answers
0
Yes. You can abort from a separate thread by setting the Http object's AbortCurrent property. You can call SynchronousRequest from a background thread, and set AbortCurrent from the main thread, or the reverse.
For example, in C++:
static DWORD WINAPI myAbortThreadProc(LPVOID lpvThreadParm)
{
CkHttp *pHttp = (CkHttp *) lpvThreadParm;
Sleep(2000);
pHttp->put_AbortCurrent(true);
return 0;
}
bool HttpTesting::qa_abortCurrentSynchronousRequest(void)
{
const char *testName = "qa_abortCurrentSynchronousRequest";
CkHttp http;
// http://www.w3.org/TR/xhtml1/DTD/xhtml---.dtd
CkHttpRequest req;
req.put_HttpVerb("GET");
req.put_Path("/TR/xhtml1/DTD/xhtml---.dtd");
// Start a thread to do the abort...
DWORD threadID;
HANDLE hThread = CreateThread(0,0,myAbortThreadProc,(void *)&http,0,&threadID);
if (hThread == NULL)
{
printf("Failed to start thread!\n");
return false;
}
else
{
CloseHandle(hThread);
}
CkHttpResponse *resp = http.SynchronousRequest("www.w3.org",80,false,req);
if (!resp) return failed(testName,http);
printf("%s\n",http.lastErrorText());
delete resp;
return succeeded(testName);
}

Chilkat Software
- 1,405
- 1
- 9
- 8