小编Mic*_*kov的帖子

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

我在控制台应用程序中的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( …
Run Code Online (Sandbox Code Playgroud)

delphi multithreading console-application omnithreadlibrary

3
推荐指数
1
解决办法
230
查看次数