Multithreading Delphi-Omnithreadlibrary,控制台应用程序中主线程的死亡
我在控制台应用程序中的BackgroundWorker(高级OmniThreadLibrary组件)中的主线程有问题。主线程(整个应用程序)中的对象在为后台任务调度工作项时立即死亡。主线程不等待OnRequestDone方法调用Multithreading Delphi-Omnithreadlibrary,控制台应用程序中主线程的死亡,multithreading,delphi,console-application,omnithreadlibrary,Multithreading,Delphi,Console Application,Omnithreadlibrary,我在控制台应用程序中的BackgroundWorker(高级OmniThreadLibrary组件)中的主线程有问题。主线程(整个应用程序)中的对象在为后台任务调度工作项时立即死亡。主线程不等待OnRequestDone方法调用 procedure TEntityIndexer.StartReindex; begin if LoadTable then // in ProcessRecords method I schedule WorkItems for BackgroundWor
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;
有什么解决方案可以解决这种情况吗?OTL依赖于其主线程中的Windows消息队列。你必须传递信息。这种情况在GUI应用程序中自然发生,但在控制台应用程序中不会发生。将消息循环添加到程序中 示例62演示了这一点: