Delphi - Omnithreadlibrary,在控制台应用程序中主线程的死亡问题

3

在控制台应用程序中,我在BackgroundWorker(高级OmniThreadLibrary组件)的主线程中遇到了问题。当它为后台任务安排WorkItems时,主线程(整个应用程序中的对象)会立即死亡。主线程不等待OnRequestDone方法被调用。

procedure TEntityIndexer.StartReindex;
begin
  if LoadTable then
    // in ProcessRecords method I schedule WorkItems for BackgroundWorker
      ProcessRecords;
  // when ProcessRecords method is done, application is at the end and
  // main thread is destoryed, so object in main thread is destroyed
  // and BackgroundWorker in object in main thread is destroyed too
end;

procedure TEntityIndexer.ProcessRecords;
var
  _id: Integer;
  _omniValue: TOmniValue;
begin
  FVTable.First;
  while not FVTable.Eof do
  begin
    _id := FVTable.FieldByName('record_id').AsInteger;
    WriteLogText(cProcesIndexLog, 'ID=' + IntToStr(_id) + '....PROCESS STARTED');

    _omniValue := TOmniValue.CreateNamed(
      [ovIdKey, _id,
      ovXMLKey, FVTable.FieldByName('mx').AsString,
      ovGenKey, FVTable.FieldByName('created_str').AsString
      ]);
    FBackgroundWorker.Schedule(FBackgroundWorker.CreateWorkItem(_omniValue));

    FVTable.Next;
  end;
end;

有没有解决这个问题的方案?
1个回答

7

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接