我正在使用 IXMLHTTPRequest2/IXMLHTTPRequest2Callback 接口发送 HTTP 请求并处理响应。有时响应回调(OnHeadersAvailable() 等)在与发送请求的线程不同的线程上调用,有时回调在发送请求的同一线程上调用,如下面的调用堆栈所示:
my.dll!xxxXMLHTTPRequest2Callback::OnHeadersAvailable(IXMLHTTPRequest2 * pXHR, unsigned long dwStatus, const wchar_t * pwszStatus) Line 185 C++
msxml6.dll!URLMONRequest::_CallOnHeadersAvailable() Line 305 C++
msxml6.dll!URLMONRequest::_OnResponse(unsigned long dwResponseCode, const wchar_t * pwszResponseHeaders, const wchar_t * pwszRequestHeaders) Line 2946 C++
msxml6.dll!URLMONRequest::OnResponse(unsigned long dwResponseCode, const wchar_t * pwszResponseHeaders, const wchar_t * pwszRequestHeaders, wchar_t * * ppwszAdditionalRequestHeaders) Line 2993 C++
msxml6.dll!URLMONRequest::URLMONRequestSink::OnResponse(unsigned long dwResponseCode, const wchar_t * szResponseHeaders, const wchar_t * szRequestHeaders, wchar_t * * pszAdditionalRequestHeaders) Line 212 C++
urlmon.dll!CINetHttp::QueryStatusOnResponseDefault() Unknown
urlmon.dll!CINetHttp::QueryStatusOnResponse() Unknown
urlmon.dll!CINetHttp::INetAsyncSendRequest() Unknown
urlmon.dll!CINetHttp::INetAsyncOpenRequest() Unknown
urlmon.dll!CINet::INetAsyncConnect() Unknown
urlmon.dll!CINet::INetAsyncOpen() Unknown
urlmon.dll!CINet::StartCommon() Unknown
urlmon.dll!CINet::Start() Unknown
msxml6.dll!URLMONRequest::send(tagVARIANT varBody) Line 838 C++
msxml6.dll!XMLHttp::send(tagVARIANT varBody) Line 549 C++
msxml6.dll!XMLHttp2::_Send(ISequentialStream * pBody, unsigned __int64 cbBody) Line 2440 C++
msxml6.dll!XMLHttp2::Send(ISequentialStream * pBody, unsigned __int64 cbBody) Line 2993 C++
我希望回调总是在不同的线程上调用,因为这被记录为异步接口。有没有一种方法可以保证始终在与发送请求的线程不同的线程上调用回调?感谢您提供任何信息。