Multithreading ISAPI DLL无法启动线程

Multithreading ISAPI DLL无法启动线程,multithreading,delphi,iis,Multithreading,Delphi,Iis,我有一个ISAPI扩展DLL,它使用线程化的帮助对象。在我的QA服务器上,线程成功执行,而在实时服务器上则没有。两种环境中的服务器硬件相同。开发语言是DelphiXe2 unit uRemoteTest2Intf; interface uses Soap.InvokeRegistry, System.Types, Soap.XSBuiltIns; type { Invokable interfaces must derive from IInvokable } IRemoteTest

我有一个ISAPI扩展DLL,它使用线程化的帮助对象。在我的QA服务器上,线程成功执行,而在实时服务器上则没有。两种环境中的服务器硬件相同。开发语言是DelphiXe2

unit uRemoteTest2Intf;

interface
uses Soap.InvokeRegistry, System.Types, Soap.XSBuiltIns;

type
  { Invokable interfaces must derive from IInvokable }
  IRemoteTest = interface(IInvokable)
  ['{9F4E3DF8-5D22-46FE-B3DC-B6CD8EE971AD}']
    function LogData(const Value: string): string; stdcall;
  end;

implementation

initialization
  InvRegistry.RegisterInterface(TypeInfo(IRemoteTest));

end.

unit uRemoteTest2Impl;

interface
uses Soap.InvokeRegistry, System.Types, Soap.XSBuiltIns, uRemoteTest2Intf, uThread;

type
  { TRemoteTest }
  TRemoteTest = class(TInvokableClass, IRemoteTest)
  private
    worker: TWorkerThread;
  public
    function LogData(const Value: string): string; stdcall;
    constructor Create; override;
    destructor Destroy; override;
  end;

implementation

uses
  uLog, Winapi.Windows, Winapi.Messages;

procedure RemoteTestFactory(out obj: TObject);
{$J+}
const
  iInstance: IRemoteTest = nil;
  instance: TRemoteTest = nil;
begin
  if instance = nil then
  begin
    instance := TRemoteTest.Create;
    instance.GetInterface(IRemoteTest, iInstance)
  end;
  obj := instance
end;

constructor TRemoteTest.Create;
begin
  inherited;
  //SetApplicationLogLevel(2);
  //SetApplicationLogFilename('c:\temp\test.txt');

  Log('Calling TRemoteTest.Create');
  worker := TWorkerThread.Create;
  worker.Start;
  if worker.Suspended then
    Log('worker is  suspended')
  else
    Log('worker is not suspended');

  Log('Called TRemoteTest.Create');
end;

destructor TRemoteTest.Destroy;
begin
  Log('Calling TRemoteTest.Destroy');
  worker.Free;
  inherited;
end;

function TRemoteTest.LogData(const Value: string): string;
begin
  Log('Calling TRemoteTest.LogData');
end;

initialization

InvRegistry.RegisterInvokableClass(TRemoteTest, RemoteTestFactory);

end.

unit uThread;

interface
uses
  System.Classes;

type
  TWorkerThread = class(TThread)
  protected
    procedure Execute; override;
  public
    constructor Create;
    destructor Destroy; override;
  end;

implementation

uses
  uLog;

constructor TWorkerThread.Create;
begin
  inherited Create(true);
  Log('Calling TWorkerThread.Create');
end;

destructor TWorkerThread.Destroy;
begin
  Log('Calling TWorkerThread.Destroy');
  inherited;
end;

procedure TWorkerThread.Execute;
begin
  NameThreadForDebugging('WorkerThread');
  Log('Executing Thread');
  while not Terminated do
  begin
    sleep(1000);
    Log('Executing thread');
  end;
  Log('Executed Thread');
end;

end.
{日志过程是引用的uLog.pas文件中的内部日志例程}


在IIS服务器上,要运行的最后一段if代码是主线程中的TWorkerThread.Start。线程的Execute方法不会被调用,该方法应该在该线程的上下文中运行。

IIS或windows日志中有任何内容吗?您需要提供有关该问题的更多信息。它可以在我的QA服务器上运行,但在现场服务器上,它没有足够的信息。如果您无法提供更多信息,请插入一些日志记录或使用调试器找出问题所在,这样您就有了更多信息,我们可以用来尝试帮助您。Thx Ken。我已经删除了发布代码中的日志调用。线程的Execute方法的第一行是一个日志调用,它永远不会被调用。调用线程构造函数中的日志代码。当我回收IIS应用程序池时,线程析构函数中的日志代码会被调用,但之前不会调用。我的直觉是IIS上有一些生存期或权限设置?嗨,Preet,这两个都没有:我简化了代码,只创建了一个从主请求处理程序派生的简单工作线程。