Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Multithreading 在Apache托管的Delphi创建的ISAPI dll中获取当前上下文ID_Multithreading_Apache_Delphi_Soap_Indy - Fatal编程技术网

Multithreading 在Apache托管的Delphi创建的ISAPI dll中获取当前上下文ID

Multithreading 在Apache托管的Delphi创建的ISAPI dll中获取当前上下文ID,multithreading,apache,delphi,soap,indy,Multithreading,Apache,Delphi,Soap,Indy,我有一个线程安全类,用于为任何给定线程获取正确的TADOConnection。这在我的可执行文件中非常有效。它归结为以下几点: function ConnectionForCurrentThread () : TADOConnection; var thread : TThread; begin thread := TThread.CurrentThread; result := adoConnectionFactory.ConnectionForID(thread.Handle);

我有一个线程安全类,用于为任何给定线程获取正确的TADOConnection。这在我的可执行文件中非常有效。它归结为以下几点:

function ConnectionForCurrentThread () : TADOConnection;
var
  thread : TThread;
begin
  thread := TThread.CurrentThread;
  result := adoConnectionFactory.ConnectionForID(thread.Handle);
end;
adoConnectionFactory最终处理一个关键部分,以返回存储在列表中的现有ADO连接,或者创建一个新的ADO连接(如果尚未为该线程句柄创建)。后来,我测试它们,用一个

if Windows.GetExitCodeThread(threadID, res) then begin
  if res <> Windows.STILL_ACTIVE then begin
    TADOConnection(connections.Objects[i]).Free;
    connections.Delete(i);
  end;
end else begin
  TADOConnection(connections.Objects[i]).Free;
  connections.Delete(i);
end;
但我不太确定这是什么背景。有什么建议吗?另一方面,如何查看给定的上下文ID不再处于活动状态,以便可以关闭其连接

这是使用delphixe和SOAP服务器应用程序(WebBroker、TWebModule等等)。
谢谢。

对于ISAPI应用程序,以下操作应该有效(假设Apache使用唯一的连接ID正确填写ISAPI ECB)


默认的Delphi XE SOAP服务器应用程序是否应该实例化WebContext?因为它是零,看起来不应该在运行中创建。是的,如果它是ISAPI应用程序,它应该自动初始化WebContext。嗯,在这种情况下,我不太确定为什么不在那个时候创建它。应用程序几乎是
CoInitFlags:=COINIT\u多线程的;应用程序初始化;Application.MaxConnections:=255;线程数:=255;Application.WebModuleClass:=WebModuleClass;应用程序。运行function ConnectionForCurrentThread () : TADOConnection;
var
  thread : TThread;
  ct : TContextThing;
  id : integer;
begin
  if WebServiceMode then begin
    ct := TContextThing.CurrentContext;
    id := ct.ContextID;
  end else begin
    thread := TThread.CurrentThread;
    id := thread.Handle;
  end;
  result := adoConnectionFactory.ConnectionForID(id);
end;
uses
  Web.WebCntxt,
  Web.Win.IsapiHttp;

if WebServiceMode then
  id := TIsapiRequest(WebContext.Request).ECB^.ConnID
else
  ...